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
- Create a new ASP.NET MVC project.
- Copy the required assemblies and QtBinaries from the WebKit installed location to project folder.
- Refer the copied assemblies in the project by using reference manager.
- Include the QtBinaries folder in the project and set Copy to Output Directory as Copy always for all files in the QtBinaries folder.
- Add button to export the web page to PDF in index.cshtml and add the following code snippet in controller.
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"); }
- Run the project and test the HTML conversion in local computer.
Publishing the project to server
- Publish the project to a local file folder.
- It will publish the required files to the local publish folder.
- Copy the published output folder to the server and host the application in IIS.
- Open the IIS manager in the server and add new website.
- Provide site name and select the physical path of the published output folder on the server.
- Get the IP address of the server after adding the website in local IIS server.
- Browse the website using the IP address and port number from the local computer. Once the website is loaded, export the webpage to PDF.
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
Sample: