1. Download HtmlRenderer.PdfSharp Nuget packages: more...
Install-Package HtmlRenderer.PdfSharp -Version 1.5.0.6
2. Create a method in C# to convert html to pdf
public static void CreatePdfFromHtml (string html)
{
Byte[] res = null;
using (MemoryStream ms = new MemoryStream())
{
var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf (html, PdfSharp.PageSize.A4);
pdf.Save(ms);
res = ms.ToArray();
}
File.WriteAllBytes("c:\\output.pdf", res);
}
Install-Package HtmlRenderer.PdfSharp -Version 1.5.0.6
2. Create a method in C# to convert html to pdf
public static void CreatePdfFromHtml (string html)
{
Byte[] res = null;
using (MemoryStream ms = new MemoryStream())
{
var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf (html, PdfSharp.PageSize.A4);
pdf.Save(ms);
res = ms.ToArray();
}
File.WriteAllBytes("c:\\output.pdf", res);
}
No comments:
Post a Comment