Free HTML to PDF in C# with the SelectPdf Community Edition

The SelectPdf Community Edition is a free HTML to PDF converter for .NET, free for personal and commercial use. It renders with the same Chromium engine as the commercial library and keeps up to 5 pages per PDF. On Windows, Linux, macOS and Docker it is the SelectPdf.HtmlToPdf.Universal package.

Compiled and run: Linux ARM64 · Linux x64 · macOS ARM64 · Windows x64

Video walkthrough · 3:46 · Watch on YouTube · Short · 1:05
§STEP BY STEP

Build it step by step.

  1. 1Install the NuGet packages

    SelectPdf.HtmlToPdf.Universal is the library, the free Community Edition. The native package carries the Chromium engine for one platform: add the one for the platform you run on.

    terminal
    dotnet add package SelectPdf.HtmlToPdf.Universal
    dotnet add package SelectPdf.Universal.Native.win-x64
    terminal
    dotnet add package SelectPdf.HtmlToPdf.Universal
    dotnet add package SelectPdf.Universal.Native.linux-x64
    terminal
    dotnet add package SelectPdf.HtmlToPdf.Universal
    dotnet add package SelectPdf.Universal.Native.linux-arm64
    terminal
    dotnet add package SelectPdf.HtmlToPdf.Universal
    dotnet add package SelectPdf.Universal.Native.osx-arm64
  2. 2Create a console app

    Any .NET 8 or .NET 10 project works. To follow along, create a console app, run the install commands above inside its folder, then replace Program.cs with the code below.

    terminal
    dotnet new console -n PdfSample
    cd PdfSample
  3. 3Import the namespace

    Program.cs · lines 1–1
    using SelectPdf.Universal;

    The free package, SelectPdf.HtmlToPdf.Universal, uses the same SelectPdf.Universal namespace as the commercial library. Next to it goes the engine package for your platform (see the install tabs).

  4. 4Create the converter

    Program.cs · lines 3–8
    // 1. The free Community Edition (SelectPdf.HtmlToPdf.Universal) has the same
    // HtmlToPdf converter and options as the commercial library.
    HtmlToPdf converter = new HtmlToPdf();
    converter.Options.PdfPageSize = PdfPageSize.A4;
    converter.Options.MarginTop = 20;
    converter.Options.MarginBottom = 20;

    HtmlToPdf and its options are the same as in the commercial library: page size, orientation and margins (in points) work as documented for it.

  5. 5Add page numbers in the footer

    Program.cs · lines 10–16
    // 2. Headers and footers are included: "Page X of Y" at the bottom right.
    converter.Options.DisplayFooter = true;
    converter.Footer.Height = 30;
    PdfTextSection pageNumbers = new PdfTextSection(0, 8, "Page {page_number} of {total_pages}  ",
        PdfFont.CreateFromSystemFont("Liberation Sans", 9f));
    pageNumbers.HorizontalAlign = PdfTextHorizontalAlign.Right;
    converter.Footer.Add(pageNumbers);

    Custom headers and footers are part of the free edition. DisplayFooter turns the footer on, and a PdfTextSection with {page_number} and {total_pages} prints "Page 1 of 5" at the bottom right of each page.

  6. 6Convert a web page

    Program.cs · lines 18–21
    // 3. Convert a web page and save the PDF.
    PdfDocument doc = converter.ConvertUrl("https://selectpdf.com/community-edition/");
    doc.Save("community-edition.pdf");
    doc.Close();

    ConvertUrl loads the page and renders it with the Chromium engine; ConvertHtmlString converts an HTML string the same way. Save writes the PDF and Close releases it.

  7. 7Check the 5-page limit

    Program.cs · lines 23–25
    // 4. A document keeps at most 5 pages: check whether the content was longer.
    HtmlToPdfResult result = converter.ConversionResult;
    Console.WriteLine($"{result.PdfPageCount} pages saved, {result.PdfPageCountBeforeLimit} before the limit");

    The free edition keeps the first 5 pages of a document. ConversionResult.PdfPageCountBeforeLimit says how many pages the content needed: here it prints "5 pages saved, 8 before the limit", so three pages were left out. Compare it with PdfPageCount to tell your users, or to switch to the commercial library.

  8. 8Run it

    terminal
    dotnet run

    The program writes community-edition.pdf to the working folder. The Community Edition needs no license key and adds no watermark.

§COMPLETE PROGRAM

The complete Program.cs.

This is the exact file our samples pipeline compiled and ran on Linux ARM64 and Linux x64 and macOS ARM64 and Windows x64 to produce the output on this page.

Program.cs
using SelectPdf.Universal;

// 1. The free Community Edition (SelectPdf.HtmlToPdf.Universal) has the same
// HtmlToPdf converter and options as the commercial library.
HtmlToPdf converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.A4;
converter.Options.MarginTop = 20;
converter.Options.MarginBottom = 20;

// 2. Headers and footers are included: "Page X of Y" at the bottom right.
converter.Options.DisplayFooter = true;
converter.Footer.Height = 30;
PdfTextSection pageNumbers = new PdfTextSection(0, 8, "Page {page_number} of {total_pages}  ",
    PdfFont.CreateFromSystemFont("Liberation Sans", 9f));
pageNumbers.HorizontalAlign = PdfTextHorizontalAlign.Right;
converter.Footer.Add(pageNumbers);

// 3. Convert a web page and save the PDF.
PdfDocument doc = converter.ConvertUrl("https://selectpdf.com/community-edition/");
doc.Save("community-edition.pdf");
doc.Close();

// 4. A document keeps at most 5 pages: check whether the content was longer.
HtmlToPdfResult result = converter.ConversionResult;
Console.WriteLine($"{result.PdfPageCount} pages saved, {result.PdfPageCountBeforeLimit} before the limit");

Open the project on GitHub → this program and the variations below, ready to dotnet run

§OUTPUT

The PDF it produces.

First page of community-edition.pdf, the PDF this sample produces
community-edition.pdf, page 1

Download community-edition.pdf ↓ the file this sample produced, unedited

§TROUBLESHOOTING

Common problems and fixes.

The PDF stops after page 5

That is the Community Edition's limit. The commercial SelectPdf.Universal library has no page limit; switch the package and keep the code.

A class such as PdfSecurityManager or PdfToText is missing

Working with existing PDFs (loading, editing, merging, signing), PDF to text, PDF to image and form filling are in the commercial library only. The free edition converts HTML and URLs to new PDFs.

The engine package for my platform

Add the engine package for the platform the app runs on (the install tabs list them), one per build. Alternatively, install one package that brings both: SelectPdf.HtmlToPdf.Windows, SelectPdf.HtmlToPdf.Linux, SelectPdf.HtmlToPdf.Linux.Arm64 or SelectPdf.HtmlToPdf.MacOS.

Text shows as boxes on Linux

The server has no fonts for that script. Arial, Times New Roman and Courier New are covered by the built-in Liberation fonts; for CJK, Arabic and other scripts see the fonts on Linux guide.

§GOOD TO KNOW

Good to know.

  • SelectPdf.HtmlToPdf.Universal is the free Community Edition of the SelectPdf HTML to PDF converter for .NET, free for personal and commercial use, on Linux x64 and ARM64, Docker, Windows and macOS on Apple Silicon. Source
  • The Community Edition generates PDF documents up to five pages long; it is a free product, not the commercial trial. Source
  • HtmlToPdfResult.PdfPageCountBeforeLimit is the number of pages the conversion produced before the 5-page limit was applied; in the full edition it always equals PdfPageCount. Source
  • The free edition includes custom headers and footers, page settings, HTTP headers and cookies, authentication, and HTML5, CSS3 and web fonts. Source
  • Loading and modifying existing PDFs, PDF to text, PDF to image and form filling need the commercial library. Source
?FAQ

Questions, answered.

Short answers about this guide. The SelectPdf.Universal documentation covers every class and option.

Yes. The SelectPdf Community Edition (NuGet package SelectPdf.HtmlToPdf.Universal) converts HTML and URLs to PDF for free, for personal and commercial use, on Windows, Linux, macOS and Docker.
A PDF document keeps up to 5 pages. Some features, such as editing existing PDFs, PDF to text and PDF to image, need the commercial library.
Yes. It is free for personal and commercial projects, including production, with no royalties or per-document fees. It is a free product, not a trial.
Replace the SelectPdf.HtmlToPdf.Universal package with SelectPdf.Universal and set your license key. The namespace and the converter API are the same, so the code does not change.