I am looking to use HtmlRenderer to convert an HTML file to a PDF file. I have seen it being mentioned on several sites that it is possible. However, I don't seem to be able to find any basic sample code to do this.
I have added the following NuGet package.
Install-Package HtmlRenderer.PdfSharp
That's about as far I have got. Any help will be greatly appreciated.
On a Windows computer, open an HTML web page in Internet Explorer, Google Chrome, or Firefox. On a Mac, open an HTML web page in Firefox. Click the “Convert to PDF” button in the Adobe PDF toolbar to start the PDF conversion. Enter a file name and save your new PDF file in a desired location.
Found a solution:
using TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator; string html = File.ReadAllText("input.htm"); PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.Letter); pdf.Save("document.pdf");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With