How to run custom javascript on wkhtmltopdf / wkhtmltoimage?

I want to run javascript on a website, but when I do this, nothing changes, I get pdf, as if I am not running the javascript result, this is an example of what I am doing:

xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltoimage --run-script "javascript:(\$(function(){ \$("div").hide()   ;}))" google.com google.png

I also have scripts without jquery, for example:

xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltopdf --run-script "javascript:(function(){ document.write("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHH"); ;})" google.com p2.pdf

But, as I said, there is no effect on pdf or png (because I tried both whtmltoimage and wkhtmltopdf).

+4
source share
2 answers

Your team uses quotes incorrectly; try the following:

--run-script "javascript:(\$(function(){ \$('div').hide()   ;}))"

Also try increasing the JavaScript delay:

--javascript-delay 1000

http://wkhtmltopdf.org/usage/wkhtmltopdf.txt

+5
source

About Question

" - .png ? png 9MB"

PNG, wkhtmltoimage, , --quality 0, 3,5 38 . , PNG , , . --quality, jpg, , .

+2

Source: https://habr.com/ru/post/1535741/


All Articles