Articles in this section
Category / Section

How to publish HTML to PDF converter to server using WebKit HTML converter

2 mins read

Converting HTML to PDF in Web application from scratch using WebKit HTML converter. This documentation contains three sections:

  • HTML to PDF conversion in local machine.
  • Publishing the project to server.
  • Troubleshooting the conversion failure in server.

Assemblies Required

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

You can get all these assemblies by installing the WebKit installer in the following link.

WebKit HTML Converter: https://www.syncfusion.com/downloadslatest-version

HTML to PDF conversion in local machine

  1. Create a new ASP.NET MVC project. Create ASP.NET Web application
  2. Copy the required assemblies and QtBinaries from the WebKit installed location to project folder. Copy Assemblies and QtBinaries
  3. Refer the copied assemblies in the project by using reference manager. Refer Copied Assemblies
  4. Include the QtBinaries folder in the project and set Copy to Output Directory as Copy always for all files in the QtBinaries folder. Include Project Copy to output directory
  5. Add button to export the web page to PDF in index.cshtml and add the following code snippet in controller. Add Button

C#

public ActionResult ExportToPDF()
{
//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = Server.MapPath("~/QtBinaries/");
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert(Request.Url.Authority);
MemoryStream stream = new MemoryStream();
//Save and return the PDF file
document.Save(stream);
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Sample.pdf");
}

 

  1. Run the project and test the HTML conversion in local computer.

Publishing the project to server

  1. Publish the project to a local file folder. Publish the project Pick a Publish target
  2. It will publish the required files to the local publish folder. Published files location
  3. Copy the published output folder to the server and host the application in IIS.
  1. Open the IIS manager in the server and add new website.
  2. Provide site name and select the physical path of the published output folder on the server. Fill published details on server
  3. Get the IP address of the server after adding the website in local IIS server.
  4. Browse the website using the IP address and port number from the local computer. Once the website is loaded, export the webpage to PDF. Published website Published Website

 

Troubleshooting the conversion failure in server

Refer to the following links for troubleshooting the conversion failure in the server.

UG: https://help.syncfusion.com/file-formats/pdf/converting-html-to-pdf#troubleshooting 

KB: https://www.syncfusion.com/kb/8208/failed-to-convert-the-webpage-exception-with-webkit-html-converter

Sample:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/HTMLtoPDF_Sample-1404315275-1396057620

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied