2

How to use wkhtmltopdf page option: --run-script inside of exec()

exec(path/to/wkhtmltopdf --run-script(???)  path/to/pdf-ed/doc  path-to-output-pdf))
Jeffz
  • 2,075
  • 5
  • 36
  • 51
  • I wrote this in a recent post here: http://stackoverflow.com/questions/25780131/executing-wkhtmltopdf-via-php-throws-error – Guppy Sep 14 '14 at 15:13
  • wkhtmltopdf works ok - no problem here, just that particular option: --run-script eludes me – Jeffz Sep 14 '14 at 15:51
  • Is this PHP? That does not look like a valid exec command, how does yours actually look like? – Joel Peltonen Sep 15 '14 at 05:25

1 Answers1

0

The --run-script argument takes JavaScript passed at the command line. NOT a script file, but actual script content.

$jsCode  = '/* JavaScript code that manipulates the DOM... */';
$webURL  = 'http://example.com';
$pdfFile = '/tmp/output.pdf';
exec('wkhtmltopdf '.
     '--run-script '.escapeshellarg($jsCode).' '.
     escapeshellarg($webURL).' '.
     escapeshellarg($pdfFile));
jimp
  • 16,999
  • 3
  • 27
  • 36