Sunday, 19 February 2017

Convert HTML to PDF in .NET

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);
}


No comments:

Setup Windows Local Account without the Internet

During the Windows setup,  On the WiFi screen, press SHIFT + F10  or  FN + SHIFT + F10  This will open the command prompt window with admini...