2X faster development
The ultimate Xamarin 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. HTML to PDF conversion is supported in Xamarin platform by using web service. Using this library, you can convert HTML to PDF in Xamarin platform. Refer to the following steps to convert a HTML to PDF in web 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] MemoryStream GetData(string value); 4.4) Include the following namespaces and code snippet in Service1.svc for converting HTML to PDF in web 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 MemoryStream GetData(string value) { return CreateDocument(value); } public MemoryStream CreateDocument(string pathURL) { //Create new HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); //Initialize the WebKit settings WebKitConverterSettings webKitSettings = new WebKitConverterSettings(); //Set the WebKit path webKitSettings.WebKitPath = Path.Combine( HostingEnvironment.ApplicationPhysicalPath, "QtBinaries"); //Set the WebKit conversion settings htmlConverter.ConverterSettings = webKitSettings; //Convert URL to pdf PdfDocument document = htmlConverter.Convert(pathURL); //Save the document MemoryStream stream = new MemoryStream(); document.Save(stream); //Sets the stream position stream.Position = 0; //Close the PDF document document.Close(); //Return the PDF stream. return stream; }
Refer to the following steps for converting HTML to PDF using the above local service.
The samples of Web service and Xamarin are attached in this article for your reference. Find the samples from the following zip files. Web service: WebRoleWebKit.zip. Xamarin sample: HtmlToPDFConversion.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. See also: How to convert HTML to PDF in UWP. An online sample link to convert HTML to PDF. Note: Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
|
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
Hello,
Do we need a service to make this work?
Thanks,
Ricky
Hi Ricky,
Since HTML to PDF conversion does not have native support in Xamarin, we need to create a web service to make use of this work around.
Regards,
Prakash V
Hello,
Is it possible to convert an html string to PDF using syncfusion?
Thanks,
Reihaneh
Hi Reihaneh,
Yes, it is possible to convert HTML string to PDF using HTML converter. As our HTML converter does not have native support in Xamarin, we need to create a web service for converting a HTML string to PDF. Kindly refer the following link for converting HTML string to PDF.
KB: https://www.syncfusion.com/kb/9890/
Regards,
Prakash V
This is very disappointing.
Hi Michael,
Currently we do not have native support for converting HTML to PDF in Xamarin. As a workaround, we can achieve convert HTML to PDF by using web service. We will revamp this KB article with complete steps and details to convert HTML to PDF in Xamarin platform.
Please let us know if you need any further assistance on this.
Regards,
Gowthamraj K