We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to preserve resources during HTML string to PDF conversion

Platform: WinForms |
Control: PDF
Tags: htmltopdf, webkit

Syncfusion HTML to PDF for .NET is used to convert webpages, SVG, MHTML, and HTML to PDF. Using this library, you can preserve resources such as image, scripts, and CSS during HTML text to PDF conversion. While converting HTML string to PDF, you have the option to specify the base URL. The base URL is a path of the resources used in the HTML string.

Assemblies required

  • Syncfusion.Compression.Base.dll
  • Syncfusion.HtmlConverter.Base.dll
  • Syncfusion.Pdf.Base.dll
  • QtBinaries folder

You can get all the previously mentioned assemblies and QtBinaries by installing the HTML converter installer available in the following link.

HTML Converterhttps://www.syncfusion.com/downloads/latest-version


  1. Install the Syncfusion.HtmlToPdfConverter.QtWebKit.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.

NuGet Installed location: C:\Users\<<user name>> \.nuget\packages\syncfusion.htmltopdfconverter.qtwebkit.winforms\XX.X.X.XX\lib. QtBinaries location

  1. Copy the QtBinaries folder from the NuGet package installed location and paste it into your application folder to use it for conversion. Copy location for QtBinaries
  2. Use the following namespaces and code snippet to preserve resources during HTML string to PDF conversion.


using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using System.IO;



Imports Syncfusion.HtmlConverter
Imports Syncfusion.Pdf
Imports System.IO



//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = @"../../QtBinaries/";
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//HTML string with image
string htmlString = "<html><body Align='Center'><br><img src=\"syncfusion_logo.gif\" alt=\"Syncfusion_logo\" width=\"200\" height=\"70\"><p> Hello World</p></body></html>";
//Path to the resources; Path of syncfusion_logo.gif
string baseUrl = Path.GetFullPath(@"../../Resources/");
//Convert HTML string to PDF
PdfDocument document = htmlConverter.Convert(htmlString, baseUrl);
//Save and close the PDF document 



'Initialize HTML to PDF converter
Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)Dim settings As WebKitConverterSettings = New WebKitConverterSettings()
'Set WebKit path
settings.WebKitPath = "../../QtBinaries/"
'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings
'HTML string with image
Dim htmlString As String = "<html><body Align='Center'><br> <img src=""syncfusion_logo.gif"" alt=""Syncfusion_logo"" width=""200"" height=""70""> <p> Hello World</p></body></html>"
Dim baseUrl As String = Path.GetFullPath("../../Resources/")
Dim document As PdfDocument = htmlConverter.Convert(htmlString, baseUrl)
'Save and close the PDF document 


HTML string

<body Align=’Center’><br>
<img src="syncfusion_logo.gif" alt="Syncfusion_logo" width="200" height="70">
<p> Hello World</p>


For the previous HTML string, provide the path of syncfusion_logo.gif as baseURL.

For example, if the above image is in “D:/temp/Resources/syncfusion_logo.gif” location, then the baseURL will be as follows,

Example baseURL: D:/temp/Resources/

Find the possible causes and solutions for missing resources while converting HTML string to PDF:

  1. Open the base URL in web browser and check the resources such as styles, scripts, and images are accessible in the machine, where the conversion takes place. If the resources are accessible in the web browser, then the converter can access the resources when converting the HTML string to PDF.  
  2. When you combine the Base URL with href link (images, styles, and scripts used in the HTML string), it should be a valid path. Otherwise, the browser/converter unable to access the resources from the base URL.
  3. Regarding OPENSSL

To convert or access the HTTTS sites, the HTML converter requires OPENSSL assemblies. If the base URL is HTTPS, make sure that your machine/server has the OPENSSL assemblies.  Refer to the prerequisites section for more information.

The following assemblies are placed in the windows system folder (for 64-bit machine, it should be placed in $SystemDrive\Windows\SysWOW64 and for 32-bit machine, it should be placed in $SystemDrive\Windows\System32),

  • libeay32.dll
  • libssl32.dll
  • ssleay32.dll
  1. Temporary HTML file 

While converting HTML string to PDF with base URL, the HTML string with Base URL is internally saved into temporary HTML file and use this file for further conversion. So, that the browser/converter can access the resources such as styles, images, and scripts from the provided base URL. 

The HTML converter preserves the output PDF document as the temporary HTML file that is displayed in web browser. So, create a temporary HTML file with HTML string and base URL, and check the contents in the web browser.

Refer to the following steps to create a temporary HTML file.   

  1. Copy the input HTML string and save it as a HTML file.   
  2. Open the HTML file in text editor and include the Base URL as base href in header tag as follows.  
    <head><BASE HREF="https://mydomain.com/"></head> 
  1. Save and view the HTML file in browser and check the contents. 

A complete working sample can be downloaded from HTMLStringtoPDF_Resource.zip

Take a moment to peruse the documentation for Converting HTML string to PDF, where you will find other options for URL to PDF, bookmarks, and hyperlinks.

An online sample link for Converting HTML to PDF.


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment
Doug Simpson
Oct 28, 2019

This is an excellent resource.

How do you handle a URL that requires interactive authentication?


Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile