问题
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.
回答1:
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");
来源:https://stackoverflow.com/questions/40431583/convert-html-to-pdf-using-htmlrenderer