Click or drag to resize
Pdf Library for .NET

HtmlToPdf Class

Html To Pdf Converter. This class offers the API needed to convert any web page url or html string to pdf.
Inheritance Hierarchy
SystemObject
  SelectPdf.UniversalHtmlToPdf

Namespace: SelectPdf.Universal
Assembly: SelectPdf.HtmlToPdf.Universal (in SelectPdf.HtmlToPdf.Universal.dll) Version: 26.4
Syntax
public class HtmlToPdf

The HtmlToPdf type exposes the following members.

Constructors
 NameDescription
Public methodHtmlToPdf Initializes an instance of the HtmlToPdf Converter.
Public methodHtmlToPdf(Int32) Initializes an instance of the HtmlToPdf Converter.
Public methodHtmlToPdf(Int32, Int32) Initializes an instance of the HtmlToPdf Converter.
Top
Properties
 NameDescription
Public propertyConversionResult Gets a reference to an object that offers information about the result of the html to pdf conversion process.
Public propertyFooter Gets a reference to an object that controls the properties of the custom footer of the generated pdf document.
Public propertyHeader Gets a reference to an object that controls the properties of the custom header of the generated pdf document.
Public propertyOptions Gets a reference to an object that controls the html to pdf conversion process and the generated pdf document properties.
Top
Methods
 NameDescription
Public methodCode exampleConvertHtmlString(String) Renders the specified HTML string and returns the result as a PDF document.
Public methodCode exampleConvertHtmlString(String, String) Renders the specified HTML string, resolving relative resources against the given base URL, and returns the result as a PDF document.
Public methodCode exampleConvertHtmlStringAsync(String) Asynchronously renders the specified HTML string and returns the result as a PDF document.
Public methodConvertHtmlStringAsync(String, String) Asynchronously renders the specified HTML string, resolving relative resources against the given base URL, and returns the result as a PDF document.
Public methodConvertHtmlStringAsync(String, CancellationToken) Asynchronously renders the specified HTML string and returns the result as a PDF document, stopping when the specified token is cancelled.
Public methodCode exampleConvertHtmlStringAsync(String, String, CancellationToken) Asynchronously renders the specified HTML string, resolving relative resources against the given base URL, and returns the result as a PDF document, stopping when the specified token is cancelled.
Public methodCode exampleConvertUrl Renders the web page at the specified URL and returns the result as a PDF document.
Public methodCode exampleConvertUrlAsync(String) Asynchronously renders the web page at the specified URL and returns the result as a PDF document.
Public methodCode exampleConvertUrlAsync(String, CancellationToken) Asynchronously renders the web page at the specified URL and returns the result as a PDF document, stopping when the specified token is cancelled.
Top
Remarks
The result of conversion is a PdfDocument object that can be further modified, saved to memory or into a file on the disk.
Example
HtmlToPdf converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.A4;
converter.Options.MarginLeft = 20;
converter.Options.MarginRight = 20;
PdfDocument doc = converter.ConvertUrl("https://www.google.com");
doc.Save("google.pdf");
doc.Close();
See Also