Asynchronous Conversion

Use the Converter.ConvertAsync static method to convert HTML to PDF asynchronously. This method offers four overloaded options for converting a URL or HTML text.

URI to PDF

Converting HTML to PDF using a URL requires passing a URI (URL or local file) and an output path for the converted PDF to the Converter.ConvertAsync method. It also accepts optional conversion options and returns if successful.

public static Task<bool> ConvertAsync(Uri uri, string outputPath, [ConversionOptions conversionOptions = null])

The following C# and VB .NET example illustrates.

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

HTML string to PDF

Converting an HTML string to an output file path asynchronously is also straightforward. The method takes an HTML string, the output path, and conversion options. However, this method also allows specifying a base path.

public static Task<bool> ConvertAsync(string inputHtml, string outputPath, [Uri basePath = null], [ConversionOptions conversionOptions = null])

The following C# and VB .NET examples illustrate.

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

Converting to a Byte Array

Converting to a byte array is accomplished using the Converter.ConvertAsync static method. It returns a byte array rather than a file. Note that when converting using input HTML, the method also supports specifying a base path.

public static Task<Byte[]> ConvertAsync(Uri uri, [ConversionOptions conversionOptions = null])
public static Task<Byte[]> ConvertAsync(string inputHtml, [Uri basePath = null], [ConversionOptions conversionOptions = null])

The following example illustrates.

byte[] vals = await Converter.ConvertAsync(resolvePath);
Dim vals As Byte() = Await Converter.ConvertAsync(resolvePath)

Refer to the Converter.ConvertAsync API documentation for more information.

GitHub

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

The relevant C# file is:

and the relevant VB .NET file is:

In this topic