4

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.

Lamloumi Afif
  • 8,941
  • 26
  • 98
  • 191
Ilya Klementiev
  • 593
  • 8
  • 12
  • What goal would you expect and why ? – Damian Leszczyński - Vash Sep 05 '14 at 14:45
  • 3
    Have you tried passing the raw html to the wkhtmltopdf (http://wkhtmltopdf.org/) command line on your machine and obtained comparable results? You could write a Powershell script to wrap this in a timer as well. – Kyle B. Sep 05 '14 at 14:56
  • Vash - Damian, i expect something about 1, maybe 2 minutes. – Ilya Klementiev Sep 05 '14 at 15:01
  • Kyle B., i will try now. thanks – Ilya Klementiev Sep 05 '14 at 15:02
  • Why are you converting a HTML page to a PDF file? If a user wants to print it as PDF, they can use a PDF printer – Chris Marisic Sep 05 '14 at 15:23
  • 1
    Who the heck sent that close vote? It's a perfectly valid question. Also, seconding @KyleB.'s suggestion. If the results are close, then maybe there's no way to optimize it. However, if passing it to the command line has faster results, I suggest using that instead. – WGS Sep 05 '14 at 15:35
  • wkhtmltopdf is not very accurate while rendering HTML pages , I found there were some issues for rendering at higher Resolutions. If accuracy is not your concern , I would definitely recommend you to use Wkhtmltopdf .. – spetzz Sep 05 '14 at 15:35
  • Chris Marisic, no, i don't show html for user. User put xml to my service, a transform it to html for printing. – Ilya Klementiev Sep 06 '14 at 04:47
  • Kyle B., yep! nice result. #echo %date% %time% 07.09.2014 20:51:04,84 #wkhtmltopdf.exe input.html output.pdf Loading pages (1/6) Counting pages (2/6) Resolving links (4/6) Loading headers and footers (5/6) Printing pages (6/6) Done #echo %date% %time% 07.09.2014 20:51:33,36 next step - understand how to use in c# – Ilya Klementiev Sep 07 '14 at 15:06
  • OK guys, I will use a temporary solution, using the launch wkhtmltopdf.exe using Process() – Ilya Klementiev Sep 08 '14 at 13:03

1 Answers1

1

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?

David Crowell
  • 3,711
  • 21
  • 28