.NET PDF Examples
Convert HTML to PDF in C# with the .NET PDF Library
The HTML-to-PDF converter is a .NET library for converting webpages, SVG, MHTML, and HTML files to PDF documents using C#. It utilizes the popular rendering engine, Blink (Google Chrome). It is reliable and accurate. The result preserves all graphics, images, text, fonts, and the layout of the original HTML document or webpage.
Watch this video to see how to convert HTML to PDF using the Syncfusion® .NET PDF Library:
Convert HTML to PDF documents in C#
Learn how to programmatically convert HTML webpages and files to PDF format in C# using the Syncfusion .NET PDF Library. This guide demonstrates URL-to-PDF and HTML-to-PDF conversion with Chrome rendering engine.
Step 1: Create a new C# Console Application project
Begin by creating a new C# Console Application project in Visual Studio or your preferred IDE to implement HTML-to-PDF conversion functionality.
Step 2: Install Syncfusion HTML to PDF Converter NuGet package
Install the Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package in your C# project from NuGet.org. This package provides the Blink-based HTML rendering engine for PDF conversion.
Step 3: Add required namespaces for HTML to PDF conversion
Import the following namespaces in your Program.cs file to access HTML converter classes and PDF document methods:
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;Step 4: Initialize the HTML to PDF converter
Create an instance of the HtmlToPdfConverter class. This converter uses the Blink rendering engine to accurately convert HTML content to PDF format.
//Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();Step 5: Convert the URL to PDF and save the document
Use the Convert method to convert a website URL to a PDF document. The converter preserves the webpage’s layout, styles, fonts, and graphics. Save the converted document using the Save method.
//Convert URL to PDF
using (PdfDocument document = htmlConverter.Convert("https://www.google.com"))
{
//Save the PDF document
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
}GitHub project
NuGet installation
Get started quickly by downloading the installer and checking license information on the Downloads page.
Table of contents
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Learning
Technical Support
