Click or drag to resize
Pdf Library for .NET

Getting Started with Html to Pdf Converter for .NET

One of the most important features of Select.Pdf Library for .NET is the Html to Pdf Converter.

HTML content can be added to a pdf document in several ways. If a complex document is created that will contain several types of pdf elements and the html content that will be added is only a small part of the total content, PdfHtmlElement objects can be used to convert web pages or raw html content and add the conversion result to the pdf document. This is better described here.

If the pdf is generated mostly as a result of an html to pdf conversion, the HtmlToPdf object should be used instead. The HtmlToPdf and related classes and properties will be described in this page and in all pages under "Html to Pdf Converter" of Select.Pdf Developers Guide.

Quick Start

Using the Html to Pdf Converter is very easy. The first thing that needs to be done is the namespace importing.

using SelectPdf;

Sample code that shows how to convert an url to pdf using Select.Pdf Library for .NET:

// instantiate a html to pdf converter object
HtmlToPdf converter = new HtmlToPdf();

// 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();

Sample code that shows how to convert raw html code to pdf using Select.Pdf Library for .NET:

// instantiate a html to pdf converter object
HtmlToPdf converter = new HtmlToPdf();

// create a new pdf document converting the html code
PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl);

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

// close pdf document
doc.Close();
Html to Pdf Converter Properties

Options - controls the html to pdf conversion process and the generated pdf document properties.

Header - controls the properties of the custom header of the generated pdf document.

Footer - controls the properties of the custom footer of the generated pdf document.

ConversionResult - offers information about the result of the html to pdf conversion process.

These properties will be described in details in the next sections of the Developers Guide.

See Also