HTML to PDF Converter Library for .NET
EVO HTML to PDF Converter for .NET and .NET Core offers full support for HTML tags,
CSS styles, SVG vector graphics, Canvas, Web Fonts, JavaScript, page breaks control with CSS styles, repeating HTML
table header and footer in PDF pages, live URLs and internal links in PDF, automatically
generated hierarchical bookmarks and table of contents, HTML in the headers and footers. The library is more than a HTML to PDF converter.
You can also use it to easily merge, split, edit and fill existing PDF documents.
|
|
|
|
|
EVO HTML to PDF Converter
|
for .Net
|
|
|
|
EVO HTML to PDF Converter library for .NET can be easily integrated in your .NET and .NET Core applications,
including ASP.NET web sites, desktop applications, Azure Cloud services to convert HTML pages and HTML strings to PDF documents,
raster images or SVG vector images.
The HTML to PDF Converter for .NET The library does not rely on external tools or
services and does not require installation or server configuration changes, supporting
simple copy deployment.
The converter offers full support for HTML tags, CSS styles, SVG vector graphics, page breaks
control with CSS styles, automatically repeated HTML table header on each PDF page, live URLs and internal
links in PDF, automatically generated bookmarks, HTML in the headers and footers, Unicode and right to left
text, PDF merge, split and edit.
There are separate libraries and downloadable ZIP packages for .NET Framework and for .NET Core platforms.
The library for .NET Framework is compatible with .NET 2.0 and .NET 4.0 and the later runtimes.
The library for .NET Core was built for .NET Standard 2.0 and is compatible with .NET Core 2.0, .NET Core 3.1, .NET Core 6.0 and later.
The libraries for .NET and .NET Core are compatible with Windows platforms. In .NET applications for Linux, macOS, Windows, Azure App Service,
Xamarin, UWP and other platforms you can use the
Cross-Platform PDF Library for .NET
which includes the HTML to PDF, Word to PDF, Excel to PDF, PDF to Text, PDF to Image, PDF to HTML and PDF Images Extractor components
from EVO PDF Toolkit in a single library under an unique namespace.
|
|
|
|
|
|
|
|
|
Compatibility |
|
|
EVO HTML to PDF Converter for .NET is compatible with any platform which supports .NET Standard 2.0 and above or .NET Framework 4.0 and above, including:
- .NET Core 8, 7, 6, 5, .NET Standard 2.0 (and above)
- .NET Framework 4.8.1, 4.7.2, 4.6.1, 4.0 (and above)
- Windows 32-bit (x86) and 64-bit (x64)
- Azure Cloud Services and Azure Virtual Machines
- Web, Console and Desktop applications
|
|
For Linux, macOS, Windows, Azure App Service, Xamarin, UWP and other platforms you can use the
Cross-Platform PDF Library for .NET
which includes the HTML to PDF, Word to PDF, Excel to PDF, PDF to Text, PDF to Image, PDF to HTML and PDF Images Extractor components
from EVO PDF Toolkit in a single library under an unique namespace.
|
|
|
|
Software Download |
|
|
The evaluation version of the EVO HTML to PDF Converter can be downloaded as a zip archive.
The software does not need installation. You can simply extract the archive into a folder and reference the
.NET assembly in your project.
Please check the Release Notes to see
the new features and the latest changes. You must read and accept our
End User License Agreement
before you download the software. Downloading the software from our website implies that you agreed the terms and conditions.
|
|
|
|
|
|
Note: After you unzip the archive into a folder make sure that the product
binaries and documentation files (the .dll and .chm files) were not blocked by Windows
OS. To unblock the file click the "Unblock"
button if this button is displayed in file properties in Windows Explorer.
|
|
The HTML to PDF converter library you can download from the link above works well both in 32-bit and 64-bit environments. The 64-bit environments offers
more memory for the executing processes and the version below is optimized to take advantage of this opportunity when converting very large HTML documents:
|
|
|
|
|
|
While the default version of the EVO HTML to PDF converter works both in 32-bit and 64-bit environments, the version optimized for 64-bit systems works only in
64-bit systems and it is not compatible with 32-bit environments.
|
|
|
|
Getting Started |
|
|
You can quickly start with the demo applications from the Samples folder of the downloaded package or you can integrate the library in your own project.
To start with your own project, first add a reference to library.
In projects targeting the .NET Framework platform you can reference directly the EvoHtmlToPdf.dll assembly from root folder of the ZIP package for .NET Framework or alternatively the
EvoPdf
or
EvoPdf.HtmlToPdf
NuGet packages.
In projects targeting the .NET Core platform you can reference the
EvoPdf.HtmlToPdf.NetCore NuGet package
or alternatively the EvoHtmlToPdf_NetCore.dll from the Bin folder of the ZIP package for .NET core, but in this case you also have to manually reference the EvoPdf.HtmlToPdf.NetCore package dependencies.
After the reference to library was added to your project you are now ready to start writing code to convert HTML to PDF in your .NET application
|
|
|
|
C# Code Samples |
|
Copy the C# code lines from the section below to use the HTML to PDF Converter component to create a PDF document from a web page or from a HTML string and save
the resulted PDF to a memory buffer for further processing, to a PDF file or send it to browser for download in ASP.NET applications.
|
At the top of your C# source file add the using EvoPdf; statement to make available the EVO HTML to PDF Converter API for your .NET application.
|
|
// add this using statement at the top of your C# file
using EvoPdf;
|
|
To convert a HTML string or an URL to a PDF file you can use the C# code below.
|
|
// create the converter object in your code where you want to run conversion
HtmlToPdfConverter converter = new HtmlToPdfConverter();
// convert the HTML string to a PDF file
converter.ConvertHtmlToFile("<b>Hello World</b> from EVO PDF !", null, "HtmlToFile.pdf");
// convert HTML page from URL to a PDF file
string htmlPageURL = "http://www.evopdf.com";
converter.ConvertUrlToFile(htmlPageURL, "UrlToFile.pdf");
|
|
To convert a HTML string or an URL to a PDF document in a memory buffer and then save it to a file you can use the C# code below.
|
|
// create the converter object in your code where you want to run conversion
HtmlToPdfConverter converter = new HtmlToPdfConverter();
// convert a HTML string to a memory buffer
byte[] htmlToPdfBuffer = converter.ConvertHtml("<b>Hello World</b> from EVO PDF !", null);
// write the memory buffer to a PDF file
System.IO.File.WriteAllBytes("HtmlToMemory.pdf", htmlToPdfBuffer);
// convert an URL to a memory buffer
string htmlPageURL = "http://www.evopdf.com";
byte[] urlToPdfBuffer = converter.ConvertUrl(htmlPageURL);
// write the memory buffer to a PDF file
System.IO.File.WriteAllBytes("UrlToMemory.pdf", urlToPdfBuffer);
|
|
To convert in your ASP.NET Core and ASP.NET MVC applications a HTML string or an URL to a PDF document in a memory buffer and then send it for download to browser you can use the C# code below.
|
|
// create the converter object in your code where you want to run conversion
HtmlToPdfConverter converter = new HtmlToPdfConverter();
// convert a HTML string to a memory buffer
byte[] htmlToPdfBuffer = converter.ConvertHtml("<b>Hello World</b> from EVO PDF !", null);
FileResult fileResult = new FileContentResult(htmlToPdfBuffer, "application/pdf");
fileResult.FileDownloadName = "HtmlToPdf.pdf";
return fileResult;
|
|
To convert in your ASP.NET Web Forms application a HTML string to a PDF document in a memory buffer and then send it for download to browser you can use the C# code below.
|
|
// create the converter object in your code where you want to run conversion
HtmlToPdfConverter converter = new HtmlToPdfConverter();
// convert a HTML string to a memory buffer
byte[] htmlToPdfBuffer = converter.ConvertHtml("<b>Hello World</b> from EVO PDF !", null);
HttpResponse httpResponse = HttpContext.Current.Response;
httpResponse.AddHeader("Content-Type", "application/pdf");
httpResponse.AddHeader("Content-Disposition",
String.Format("attachment; filename=HtmlToPdf.pdf; size={0}",
htmlToPdfBuffer.Length.ToString()));
httpResponse.BinaryWrite(htmlToPdfBuffer);
httpResponse.End();
|
|
|
|
Features
|
|
|
|
|
|
|
|
|
|
|
|
|
C# Full Code Sample for ASP.NET |
|
|
EVO HTML to PDF Converter for .NET API allows you to convert a HTML document to PDF in just a few lines a code. The programming interface is
also very rich and allows you customize the generated PDF document in various ways. The code below is copied from the Getting Started demo for
HTML to PDF Converter that you can find in the Samples folder of the software Zip package.
|
protected void convertToPdfButton_Click(object sender, EventArgs e)
{
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
// Set license key received after purchase to use the converter in licensed mode
// Leave it not set to use the converter in demo mode
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
// Set HTML Viewer width in pixels which is the equivalent in converter of the browser window width
htmlToPdfConverter.HtmlViewerWidth = int.Parse(htmlViewerWidthTextBox.Text);
// Set HTML viewer height in pixels to convert the top part of a HTML page
// Leave it not set to convert the entire HTML
if (htmlViewerHeightTextBox.Text.Length > 0)
htmlToPdfConverter.HtmlViewerHeight = int.Parse(htmlViewerHeightTextBox.Text);
// Set PDF page size which can be a predefined size like A4 or a custom size in points
// Leave it not set to have a default A4 PDF page
htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = SelectedPdfPageSize();
// Set PDF page orientation to Portrait or Landscape
// Leave it not set to have a default Portrait orientation for PDF page
htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = SelectedPdfPageOrientation();
// Set the maximum time in seconds to wait for HTML page to be loaded
// Leave it not set for a default 60 seconds maximum wait time
htmlToPdfConverter.NavigationTimeout = int.Parse(navigationTimeoutTextBox.Text);
// Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
// Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
if (conversionDelayTextBox.Text.Length > 0)
htmlToPdfConverter.ConversionDelay = int.Parse(conversionDelayTextBox.Text);
// The buffer to receive the generated PDF document
byte[] outPdfBuffer = null;
if (convertUrlRadioButton.Checked)
{
string url = urlTextBox.Text;
// Convert the HTML page given by an URL to a PDF document in a memory buffer
outPdfBuffer = htmlToPdfConverter.ConvertUrl(url);
}
else
{
string htmlString = htmlStringTextBox.Text;
string baseUrl = baseUrlTextBox.Text;
// Convert a HTML string with a base URL to a PDF document in a memory buffer
outPdfBuffer = htmlToPdfConverter.ConvertHtml(htmlString, baseUrl);
}
// Send the PDF as response to browser
// Set response content type
Response.AddHeader("Content-Type", "application/pdf");
// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("{0}; filename=Getting_Started.pdf; size={1}",
openInlineCheckBox.Checked ? "inline" : "attachment", outPdfBuffer.Length.ToString()));
// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);
// End the HTTP response and stop the current page processing
Response.End();
}
|
|
|
|
C# Full Code Sample for MVC |
|
|
EVO HTML to PDF Converter for .NET can be used in any type of .NET application including ASP.NET MVC websites.
The code below is copied from the Getting Started demo for
MVC that you can find in the Samples\Other\Mvc folder of the software Zip package.
|
[HttpPost]
public ActionResult ConvertHtmlToPdf(FormCollection collection)
{
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
// Set HTML Viewer width in pixels which is the equivalent in converter of the browser window width
htmlToPdfConverter.HtmlViewerWidth = int.Parse(collection["htmlViewerWidthTextBox"]);
// Set HTML viewer height in pixels to convert the top part of a HTML page
// Leave it not set to convert the entire HTML
if (collection["htmlViewerHeightTextBox"].Length > 0)
htmlToPdfConverter.HtmlViewerHeight = int.Parse(collection["htmlViewerHeightTextBox"]);
// Set PDF page size which can be a predefined size like A4 or a custom size in points
// Leave it not set to have a default A4 PDF page
htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = SelectedPdfPageSize(collection["pdfPageSizeDropDownList"]);
// Set PDF page orientation to Portrait or Landscape
// Leave it not set to have a default Portrait orientation for PDF page
htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = SelectedPdfPageOrientation(collection["pdfPageOrientationDropDownList"]);
// Set the maximum time in seconds to wait for HTML page to be loaded
// Leave it not set for a default 60 seconds maximum wait time
htmlToPdfConverter.NavigationTimeout = int.Parse(collection["navigationTimeoutTextBox"]);
// Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed
// Set this property to 0 if you don't need to wait for such asynchcronous operations to finish
if (collection["conversionDelayTextBox"].Length > 0)
htmlToPdfConverter.ConversionDelay = int.Parse(collection["conversionDelayTextBox"]);
string url = collection["urlTextBox"];
// Convert the HTML page given by an URL to a PDF document in a memory buffer
byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(url);
// Send the PDF file to browser
FileResult fileResult = new FileContentResult(outPdfBuffer, "application/pdf");
fileResult.FileDownloadName = "Getting_Started.pdf";
return fileResult;
}
|
|