What's the fastest way to convert Html to Pdf?
I have some "big" html files 4Mb +.
Then I convert one file to PDF via Pechkin ( .NET Wrapper for WkHtmlToPdf static DLL ). I can sleep peacefully for about 3-5 minutes.
The output PDF is 2Mb + and has about 500 pages inside.
var html = "...html...";
var data = HtmlToPdf2(res);
Console.WriteLine("HtmlToPdf2 done: " + sw.Elapsed);
...
private static byte[] HtmlToPdf2(string html)
{
var pechkin = new SimplePechkin(new GlobalConfig());
var pdf = pechkin.Convert(new ObjectConfig()
.SetLoadImages(true)
.SetZoomFactor(1.5)
.SetPrintBackground(true)
.SetScreenMediaType(true)
.SetCreateExternalLinks(true)
,html);
}
My stopwatch says:
Start: 00:00:00.0007693
TransformXMLToHTML done: 00:00:03.6661490
HtmlToPdf2 done: 00:03:50.7784590
WriteAllBytes done: 00:03:50.7871326
My users will cry when they wait that long.
+3
source to share