2X faster development
The ultimate ASP.NET Core UI toolkit to boost your development speed.
Syncfusion HTML to PDF for .NET used to convert webpages, SVG, MHTML, and HTML to PDF. Using this library, you can convert HTML to PDF in ASP.NET Core Windows. Steps to convert HTML to PDF in ASP.NET Core Windows programmatically:
C# using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO; using Microsoft.AspNetCore.Hosting;
//To get content root path of the project private readonly IHostingEnvironment _hostingEnvironment; public HomeController(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; } public IActionResult ExportToPDF() { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesWindows"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.google.com"); MemoryStream stream = new MemoryStream(); document.Save(stream); return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Output.pdf"); }
A complete working sample can be downloaded from HTMLtoPDF_Windows.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. |
2X faster development
The ultimate ASP.NET Core UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
trail version or open source?
Hi Hasibul,
The HTML converter alone, does not requires any licensing. We are providing separate HTML converter add-on for file format licensing. Please refer below links to install the HTML converter installer.
UG: https://help.syncfusion.com/file-formats/pdf/converting-html-to-pdf#steps-to-download-the-html-converter-installer
Regards,
Sowmiya L
hi Is it possible to put headers and footers for all pages?
Hi yeadam,
Thank you for contacting Syncfusion support.
Currently, our HTML converter does not have direct support for adding a header/footer from the HTML file. As a workaround, we can convert each HTML data (Header, body (actual HTML), footer) to PDF separately and then draw it in the new PDF document as it looks like the header and footer are added. Can you please refer to the below link for adding HTML as header and footer in PDF while converting HTML to PDF (Net Framework),
KB (as HTML): https://www.syncfusion.com/kb/8196/how-to-add-html-as-header-and-footer-in-pdf-while-converting-html-to-pdf
KB: https://www.syncfusion.com/kb/8381/how-to-add-pdf-header-and-pdf-footer-while-converting-html-to-pdf
Please let us know if you need any further assistance on this.
Regards,
Gowthamraj K
I am getting blank page as pdf output, in .net core 3.1 and binaries are 19. something, same code.
Hi Manoj,
Thank you for contacting Syncfusion support.
Our HTML converter may generate blank PDFs while converting HTTPS sites to PDF. For converting HTTPS sites to PDF, the WebKit rendering engine requires OPENSSL libraries. So, please make sure the OPENSSL assemblies are available in the machine where the conversion takes place. Please refer to the below links for more details,
Prerequisites - https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit#openssl
Troubleshooting - https://help.syncfusion.com/file-formats/pdf/converting-html-to-pdf#troubleshooting
However, the below mentioned OPENSSL assemblies can be placed in the Windows system folder of the machine. (for 64-bit machine, it should be place in $SystemDrive\Windows\SysWOW64 and for 32-bit machine, it should be place in $SystemDrive\Windows\System32).
• libeay32.dll • libssl32.dll • ssleay32.dll
If you running the application in docker, you can copy and paste the OPENSSL assemblies files inside the QtBinaries folder in your application.
Kindly try the conversion with OPENSSL assemblies and let us know the result.
Regards,
Gowthamraj K