HTML to PDF
Add this nuget package
HtmlRenderer.PdfSharp
Generate a PDF documentstring htmlString = "<h1>Document</h1> <p>This is an HTML document which is converted to a pdf file.</p>";
PdfDocument pdfDocument = PdfGenerator.GeneratePdf(htmlString, PageSize.A4);
To save to diskpdfDocument.Save("C:/temp/HTML to PDF Document.pdf");
To convert to byte arrayusing (MemoryStream ms = new MemoryStream())
{
pdfDocument.Save(ms);
byte[] byteArray = ms.ToArray();
....
}
Comments
Post a Comment