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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to publish HTML to PDF converter to server

Platform: ASP.NET MVC |
Control: PDF |
Published Date: June 14, 2018 |
Last Revised Date: April 25, 2019

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:

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

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

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