What the fastest way to convert Html to Pdf?

3.3k Views Asked by At

I have some "big" html files 4Mb+.

Then i convert one file to PDF via Pechkin (.NET Wrapper for WkHtmlToPdf static DLL) I can safely go to sleep about 3-5 minutes.

Output PDF has 2Mb+ and 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 say:

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 so long.

1

There are 1 best solutions below

1
On

I think creating a 500 page PDF in 3-5 minutes is quite reasonable. Maybe this can be pushed into a batch job, allowing the users to do something else for a while?