nsssayom
nsssayom

Reputation: 374

easiest way to output HTML file as PDF using VB.NET

I have generated an HTML file in my application. Now I want to output that as a PDF file. How to do that easily with VB.NET? The process must be offline and I can't use any paid library or API.

Upvotes: 1

Views: 3764

Answers (1)

Sanjay Dwivedi
Sanjay Dwivedi

Reputation: 749

I have write easiest way to write html to pdf code using NRerco Pdf library which available free, Install nuget package

PM > Install-Package NReco.PdfGenerator

      Create HtmltoPdf()
       {
       if (System.IO.File.Exists("HTMLFile.html"))
        {
            System.IO.File.Delete("HTMLFile.html");
        }

        System.IO.File.WriteAllText("HTMLFile.html", html);
        var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
        if (System.IO.File.Exists("export.pdf"))
        {
            System.IO.File.Delete("export.pdf");
        }

        htmlToPdf.GeneratePdfFromFile("HTMLFile.html", null, "export.pdf");
   }

Upvotes: 2

Related Questions