◆C# / ASP.NET SAMPLE · GETTING STARTED

HTML to PDF Converter

Enter the address of a web page and click Create PDF. Free, no signup. Below is the shortest C# code that does the same.

Rendering Engine:

Url:


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 HTML to PDF converter

This is the simplest way to turn a web page into a PDF: enter its address and click Create PDF. The converter uses the same engine as the SelectPdf library for .NET; the default Chromium engine renders HTML5, CSS3 and JavaScript, and the older WebKit engines are available too.

The C# code below is the shortest form of the conversion: create the converter, convert the URL, save the PDF. For the page size, orientation and page width, use the URL to PDF converter; to convert HTML you paste, use the HTML code to PDF converter.

Questions

Enter the page's address in the Url box and click Create PDF. The PDF downloads as soon as the conversion is done. For the page size, orientation and page width, use the URL to PDF converter.
Yes. Paste the code into the HTML code to PDF converter.
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.
Chromium, the default, which renders HTML5, CSS3 and JavaScript, and the older WebKit and WebKit Restricted engines.
Create an HtmlToPdf object, call ConvertUrl (or ConvertHtmlString for HTML code), then save and close the PdfDocument it returns. The code of this page, below, does exactly that.

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 html_to_pdf_converter : System.Web.UI.Page
    {
        protected void BtnCreatePdf_Click(object sender, EventArgs e)
        {
            RenderingEngine renderingEngine =
                (RenderingEngine)Enum.Parse(typeof(RenderingEngine), DdlRenderingEngine.SelectedValue, true);

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

            converter.Options.RenderingEngine = renderingEngine;

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

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

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