1

I am using wkhtmltopdf on Ubuntu 18.04 LTS from command line and am trying to create a pdf from a webpage. The webpage content is updated once a day and filled with current information by javascript. When I use wkthmltopdf it renders all the "bare"/"empty" HTML but without current information included by the javascript, as if the javascript has not yet been loaded for the PDF or just ignored.

I am using wkhtmltopdf --javascript-delay 60000 --no-stop-slow-scripts --enable-javascript https://example.com/ test.pdf Do you know how to create the pdf after the javascript has been loaded and filled the webpage with current information?

Vroni
  • 347
  • 1
  • 5
  • 16
  • 1
    try to debug javascript. ref: https://stackoverflow.com/questions/17151755/debugging-javascript-in-wkhtmltopdf – Nitin Jan 08 '21 at 09:21
  • Thanks for your suggestion, actually it seems like it was a minor problem in my javascript. The debugging showed a SyntaxError: (Parse error). Previously I used for ... of in the javascript and now changed to a for .. in loop, which seems to have solved the problem. Though I don't quite understand why this solved the problem? – Vroni Jan 08 '21 at 10:13
  • 1
    for of is ES6 (javascript version), wkhtmltopdf probably use ES5 – Daphoque Jan 08 '21 at 10:19

2 Answers2

1

My solution:

After debugging the javascript via wkhtmltopdf (added option --debug-javascript) as @Nitin suggested I found that I had a SyntaxError (parse error).

I changed parts of the javascript from a "for..of" to "for..in" loop. This solved the problem an the pdf was created correctly. Thanks @Daphoque for explaining that this is probably due to the javascript version used by wkhtmltopdf.

Vroni
  • 347
  • 1
  • 5
  • 16
0

I had an issue like this with jquery, but it was working fine with vanilla js. Are you using javascript library ?

Daphoque
  • 4,421
  • 1
  • 20
  • 31
  • I use ''. However please see my comment above I seem to have solved the problem by changing a minor piece of code in the javascript. I am surprised this actually helped.. – Vroni Jan 08 '21 at 10:15