Web/HTML to PDF

Apryse SDK allows you to convert html pages to PDF documents.

Convert HTML to PDF in Xamarin.Android

This tutorial only applies to Xamarin.Android. See Xamarin.iOS equivalent here .

HTML to PDF conversion is available for Android API 19 and above.

Internet connection is not required when converting local HTML files. However, it is required for converting HTTP/HTTPS links.

The HTML to PDF conversion API accepts different sources, such as HTTP/HTTPS URLs, HTML strings, and everything that can be loaded in a WebView.

To convert a link URL to PDF, simply:

C#

1HTML2PDF hTML2PDF = new HTML2PDF(this);
2hTML2PDF.FromUrl("http://developer.android.com/about/index.html");
3hTML2PDF.ConversionFinished += (sender, e) =>
4{
5 // do something with e.PdfOutput
6};
7hTML2PDF.ConversionFailed += (sender, e) =>
8{
9 // error handling
10};

From HTML string

To convert an HTML string to PDF, simply:

C#

1HTML2PDF hTML2PDF = new HTML2PDF(this);
2hTML2PDF.FromHTMLDocument(myBaseUrl, myHtmlData);
3hTML2PDF.ConversionFinished += (sender, e) =>
4{
5 // do something with e.PdfOutput
6};
7hTML2PDF.ConversionFailed += (sender, e) =>
8{
9 // error handling
10};

where myBaseUrl is the URL to use as the page's base URL. If null defaults to about:blank and myHtmlData is a String of data in the UTF-8 encoding. Click here for more info.

From other sources

If none of the above fit your needs, you can also pass in a WebView directly for conversion:

C#

1HTML2PDF hTML2PDF = new HTML2PDF(myWebview);
2hTML2PDF.DoHtml2Pdf();
3hTML2PDF.ConversionFinished += (sender, e) =>
4{
5 // do something with e.PdfOutput
6};
7hTML2PDF.ConversionFailed += (sender, e) =>
8{
9 // error handling
10};

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales