Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert HTML to PDF using HtmlRenderer [closed]

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.

like image 778
slayernoah Avatar asked Nov 04 '16 20:11

slayernoah


People also ask

How do I automatically convert HTML to PDF?

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.


1 Answers

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"); 
like image 125
slayernoah Avatar answered Oct 07 '22 13:10

slayernoah