Convert a URL (web page) to PDF
Convert full web pages to PDF. The source can be a URL or a local HTML file.
ExpertPdf is an easy to use, yet powerful PDF library for .NET, with an HTML to PDF converter you can add to any .NET application in a few minutes.
Convert web pages, HTML files or HTML strings to PDF with HTML5, CSS3, SVG and JavaScript, headers and footers, page breaks, bookmarks and digital signatures.
Documentation · Online samples · NuGet · NuGet for .NET Framework · Download .zip (v22.0.0) · Free online converter
Twenty-four capabilities, grouped by where they act: how you give the converter its input, how the document is laid out, what comes out, and how the HTML is rendered.
URLs, HTML strings and local files, with or without authentication, rendered as screen or print media.
Convert full web pages to PDF. The source can be a URL or a local HTML file.
Convert raw HTML. Give a base URL when the HTML references external CSS files or images.
HTTP authentication with a user name and password, or a login form, by passing the session cookies to the converter.
Many websites have printer-friendly style sheets. Convert the page as rendered with @media print instead of the default @media screen.
Page size, orientation and margins, headers and footers, page breaks, part of a page, hidden elements, several pages in one PDF.
Full control of the PDF page size, orientation and margins.
Headers and footers on every PDF page, with full HTML support, images, text and page numbers.
Page breaks are inserted automatically without cutting lines of text or images. Add your own with the page-break-before and page-break-after CSS styles.
Convert only one section of the web page, given by an HTML element id or a CSS selector.
Leave out elements such as a Print button or a menu, chosen with CSS selectors.
With the Chromium engine, the last page ends where the HTML content ends, with no trailing blank page or empty space.
Add several HTML pages to the same PDF, and merge existing PDF documents with the one being generated.
A file, a stream, bytes or a document object, with links, bookmarks, security, signatures and element positions.
Write the PDF to a file or a stream, get it as a byte array, or get a PDF document object to change further.
Links from the web page stay clickable in the PDF. You can also turn them off.
Create bookmarks yourself, or generate them automatically from chosen tags or CSS classes of the page.
Sign the PDF digitally, set user and owner passwords, and choose what readers may print, copy or change.
A tagged PDF, with the structure of the page, for screen readers and accessibility checks, with the Blink and Chromium engines.
PDF/A-1b, PDF/A-2b, PDF/A-3b, PDF/A-3u and PDF/A-3a documents for long-term archiving, and PDF/X-1a for print.
Get where chosen HTML elements were placed in the PDF, for example where an image from the page ended up.
HTML5, CSS3, SVG and JavaScript, web fonts, a choice of engines and of when the conversion starts.
HTML5, CSS3, JavaScript, canvas and SVG, rendered the way a browser shows them.
Locally installed TTF and OTF fonts, and web fonts in TTF or WOFF format.
Chromium (CEF 154) for modern pages, Blink (Chromium 148), the internal WebKit engine with no third-party dependencies, WebKit2 and, on .NET Framework, Internet Explorer, selected with one property.
Cap how long one conversion may take with MaxConversionTime, and convert asynchronously with methods that take a cancellation token.
Send HTTP POST parameters with the request, convert only some pages, wait for a window status, convert without network access, and turn WebGL on when a page needs it.
Start the conversion when the page finishes loading, after a delay, or from a JavaScript call when your page decides it is ready.
The main properties of the PdfConverter class. All of them are described in the API reference and used in the C# and VB.NET samples.
CustomPdfPageSize.
AddHtmlToPdfArea), shown on the first, odd or even pages.
ShowPageNumber, PageNumberingFormatString).
@media print styles instead of @media screen.
The latest releases of the HTML to PDF Converter. The version history lists every release since version 2.0.
Full C# and VB.NET samples for ASP.NET, ASP.NET MVC, ASP.NET Core Razor Pages and Windows Forms ship with the download. The documentation walks through the options.
using ExpertPdf.HtmlToPdf; var converter = new PdfConverter(); converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; converter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait; converter.PdfDocumentOptions.ShowFooter = true; converter.PdfFooterOptions.ShowPageNumber = true; // From a URL, or from HTML with GetPdfBytesFromHtmlString(html, baseUrl) byte[] pdf = converter.GetPdfBytesFromUrl("https://www.example.com/"); File.WriteAllBytes("document.pdf", pdf);
Common questions about input, output, page control and rendering.
page-break-before, page-break-after and page-break-inside styles.RenderingEngine property. The Chromium engine comes in its own NuGet packages, ExpertPdf.HtmlToPdf.Chromium.Windows and ExpertPdf.HtmlToPdf.NetCore.Chromium.Windows.Tagged produces a tagged, accessible PDF (PDF/UA-1). PdfStandardSubset produces PDF/A-1b, PDF/A-2b, PDF/A-3b, PDF/A-3u and PDF/A-3a (tagged) and PDF/X-1a documents.GetPdfBytesFromUrlAsync, GetPdfBytesFromHtmlStringAsync and SavePdfFromUrlToFileAsync return a Task and take a cancellation token, on .NET Framework 4.0 and newer and on .NET Core and .NET 5 to .NET 11. MaxConversionTime limits how long one conversion may take.ConversionDelay, or when your own JavaScript calls the converter, with StartupMode.Manual.Download the free evaluation with C# and VB.NET samples for ASP.NET, ASP.NET MVC, ASP.NET Core Razor Pages and Windows Forms. When you are ready, license it on the pricing page.