0

I m tring to generate pdf from a html page (angular 2 & highchart).

Method htmlToPdf.GeneratePdfFromFile("http://plnkr.co/edit/c4ojcIRVOOwq7xmk9kfx?p=preview", null, "export.pdf") returns blank page.

But https://www.highcharts.com/demo/polar returns perfect highchart.

Is there are any solution for this.

Thanks,

Amal Fernando
  • 31
  • 1
  • 5

1 Answers1

0

Internally NReco.PdfGenerator executes wkhtmltopdf, and it can render SVG-based Highcharts. In your case problem is in the angular2-related JS code, for some reason it executes with an error. You can get this error by adding "--javascript-debug" option:

var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
htmlToPdf.LogReceived += (sender,a) => {
    Console.WriteLine("---> {0}", a.Data);
};
htmlToPdf.CustomWkHtmlArgs = " --javascript-debug --javascript-delay 3000 "

(LogReceived handles lines from wkhtmltopdf console log).

Don't forget that wkhtmltopdf is based on WebKit-QT 4.x and it is able to execute only "classic" ES5 javascript.

I may recommend to avoid usage of SPA frameworks like Angular2 or ReactJS for producing HTML that used as template for PDF. As alternative, you can produce HTML with Angular2 in the web browser (or nodejs) and then pass this HTML to PdfGenerator for PDF generation.

Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34