var htmlContent = String.Format("<body>Hello world: {0}</body>", DateTime.Now);
var pdfBytes = (new NReco.PdfGenerator.HtmlToPdfConverter()).GeneratePdf(htmlContent);
//https://www.nrecosite.com/doc/NReco.PdfGenerator/
// 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");
}
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using System.IO;
namespace HTML_File_To_PDF
{
class Program
{
static void Main(string[] args)
{
//Initialize the HTML to PDF converter with the Blink rendering engine.
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
//Set the BlinkBinaries folder path.
blinkConverterSettings.BlinkPath = @"../../../../../BlinkBinariesWindows/";
//Assign Blink converter settings to HTML converter.
htmlConverter.ConverterSettings = blinkConverterSettings;
//Convert HTML string to PDF.
PdfDocument document = htmlConverter.Convert("<h1>Hello world</h1>","");
FileStream fileStream = new FileStream("Sample.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
//Save and close the PDF document .
document.Save(fileStream);
document.Close(true);
}
}
}