HTML to PDF Conversion

Use the Converter.Convert static method to convert HTML from a URI or a text string. DynamicPDF HTML Converter supports converting HTML from a URI (URL or a local file) or from a text string. This method also supports returning a byte array rather than specifying an output path.

URI to PDF

Converting HTML to PDF using a URL or local file requires passing a URI and an output path to save the converted PDF document. The method also allows passing optional conversion options.

public static void Convert(Uri uri, string outputPath, [ConversionOptions conversionOptions = null])

Converting a URL to a PDF is straightforward, as the following C# and VB .NET examples illustrate.

Converter.Convert(new Uri("http://www.google.com"), "output.pdf");
Converter.Convert(New Uri("http://www.google.com"), "output.pdf")

HTML String to PDF

Converting an HTML document to PDF using HTML from a string is also straightforward. The method takes an input string of HTML, an output path, an optional base path, and optional conversion options.

public static void Convert(string inputHtml, string outputPath, [Uri basePath = null], [ConversionOptions conversionOptions = null])

The following C# and VB .NET examples illustrate.

Converter.Convert(htmlString, "output.pdf");
Converter.Convert(htmlString, "output.pdf")

Converting to a Byte Array

Converting to a byte array Converter.Convert static method to return a byte array rather than specifying an output file. The input can either be a URI or a string.

URI to Byte

public static Byte[] Convert(Uri uri, [ConversionOptions conversionOptions = null])

HTML String to Byte

public static Byte[] Convert(string inputHtml, [Uri basePath = null], [ConversionOptions conversionOptions = null])

The following example illustrates converting using a URI to output a PDF.

Uri document = new Uri("https://cnn.com");
byte[] output = Converter.Convert(document);
Dim document As Uri = New Uri("https://cnn.com")
Dim output As Byte() = Converter.Convert(document)

GitHub

An example demonstrating conversion using DynamicPDF HTML Converter is available on GitHub.

The relevant C# files are:

and the relevant VB .NET files are:

In this topic