◆C# / ASP.NET SAMPLE

URL to PDF Converter

Enter the address of a web page, choose the page size and click Create PDF. Free, no signup. The C# code behind this converter is below.

Url:

Pdf Page Size:


Pdf Page Orientation:


Web Page Width:
px

Web Page Height:
px
(leave empty to auto detect,
or set it to leave out the content below)

Rendering Engine:

Free to use, no signup. Every page of the PDF carries a “Demo Version” watermark, which a SelectPdf library license removes. A page that has not loaded within 30 seconds fails.

Do this in your own app

ANY LANGUAGE

HTML to PDF API

Get a free API key: 7-day trial, 200 conversions, no credit card.

curl https://selectpdf.com/api2/convert/ \
  -d "key=YOUR_KEY" \
  -d "url=https://example.com" \
  -o document.pdf
Get a free API key
C# / VB.NET

.NET library

Install from NuGet and convert in a few lines.

HtmlToPdf converter = new HtmlToPdf();
PdfDocument doc = converter.ConvertUrl("https://example.com/");
doc.Save("document.pdf");
doc.Close();
See the .NET library

Free Community Edition

Free for commercial use, up to 5 pages per PDF.

Get the Community Edition

About this URL to PDF converter

This converter loads the web page at the address you enter and saves it as a PDF document, using the same engine as the SelectPdf library for .NET. The default Chromium engine renders HTML5, CSS3 and JavaScript; the converter also offers the older WebKit engines.

Choose the PDF page size (A1 to A5, Letter, Half Letter, Ledger or Legal) and orientation, and the width of the browser window the page is laid out in: 1,024 pixels by default. Leave the height empty to convert the whole page, or enter a height to leave out what is below it. To convert HTML you have rather than a live page, use the HTML code to PDF converter.

Questions

Enter the page's address in the Url box, choose the page size and orientation, and click Create PDF. The PDF downloads as soon as the conversion is done.
Yes. The online converter is free to use and needs no signup. Every page of the PDF carries a “Demo Version” watermark, which a SelectPdf library license removes.
Yes. The default Chromium engine renders the page's HTML5, CSS3 and JavaScript before it creates the PDF. The converter also offers the older WebKit and WebKit Restricted engines.
The width is the width of the browser window the page is laid out in: 1,024 pixels by default. Leave the height empty to convert the whole page, or enter a height to leave out what is below it.
Create an HtmlToPdf object, call ConvertUrl with the page's address, and save the PdfDocument it returns. The complete C# code of this page is below. From any other language, use the HTML to PDF API.

C# / ASP.NET code for this converter

Sample code · C#
using SelectPdf;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SelectPdf.Samples
{
    public partial class convert_url_to_pdf : System.Web.UI.Page
    {
        protected void BtnCreatePdf_Click(object sender, EventArgs e)
        {
            RenderingEngine renderingEngine =
                (RenderingEngine)Enum.Parse(typeof(RenderingEngine), DdlRenderingEngine.SelectedValue, true);

            // read parameters from the webpage
            string url = TxtUrl.Text;

            string pdf_page_size = DdlPageSize.SelectedValue;
            PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), 
                pdf_page_size, true);

            string pdf_orientation = DdlPageOrientation.SelectedValue;
            PdfPageOrientation pdfOrientation = 
                (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), 
                pdf_orientation, true);

            int webPageWidth = 1024;
            try
            {
                webPageWidth = Convert.ToInt32(TxtWidth.Text);
            }
            catch { }

            int webPageHeight = 0;
            try
            {
                webPageHeight = Convert.ToInt32(TxtHeight.Text);
            }
            catch { }

            // instantiate a html to pdf converter object
            HtmlToPdf converter = new HtmlToPdf();
            converter.Options.MaxPageLoadTime = Global.MaxPageLoadTime;

            converter.Options.RenderingEngine = renderingEngine;

            // set converter options
            converter.Options.PdfPageSize = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;
            converter.Options.WebPageWidth = webPageWidth;
            converter.Options.WebPageHeight = webPageHeight;
            // a height alone only sizes the viewport; fixing the size cuts the content to it
            converter.Options.WebPageFixedSize = webPageHeight > 0;

            // create a new pdf document converting an url
            PdfDocument doc = converter.ConvertUrl(url);

            // save pdf document
            doc.Save(Response, false, "Sample.pdf");

            // close pdf document
            doc.Close();
        }
    }
}