2X faster development
The ultimate ASP.NET Web Forms UI toolkit to boost your development speed.
The Syncfusion HTML to PDF converter for .NET is used to convert webpages, SVG, MHTML and HTML to PDF. Using this library, you can convert HTML to PDF in WCF service using C# and VB.NET. Refer to the following steps to convert a HTML to PDF in WCF service:
The following steps are used to create a WCF service for conversion:
4.1) Include QtBinaries folder to the project.
4.2) Then, set Copy to output directory to copy if newer to all the QtBinaries (All files including inner folders and files). 4.3) Include new OperationContract in the IService1 interface. [OperationContract] byte[] ConvertHtmlToPdf(string url); 4.4) Include the following namespaces and code snippet in Service1.svc for converting HTML to PDF in WCF service. Refer to the following link for more information. UG: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit#url-to-pdf // [C# Code] using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO; using System.Web.Hosting;
public byte[] ConvertHtmlToPdf(string url) { //Initialize HTML to PDF converter with WebKit rendering engine HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings webConverterSettings = new WebKitConverterSettings(); //Set the QtBinaries folder path webConverterSettings.WebKitPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "QtBinaries"); //Assign WebKit converter settings to HTML converter htmlConverter.ConverterSettings = webConverterSettings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert(url); MemoryStream ms = new MemoryStream(); // Save and close the document. document.Save(ms); document.Close(true); ms.Position = 0; return ms.ToArray(); }
Refer to the following steps for converting HTML to PDF using the above local service.
The samples of WCF service and console sample are attached in this article for your reference. Find the samples from the following zip files. WCF service: WebRoleWebKit_WCFService.zip. Console sample: WebKitConsole_Sample.zip. Take a moment to peruse the documentation for Converting HTML to PDF, where you will find various options for URL to PDF, HTML string to PDF, and Hyperlinks. Refer here to explore the rich set of Syncfusion Essential PDF features. |
2X faster development
The ultimate ASP.NET Web Forms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.