Skip to content

Instantly share code, notes, and snippets.

@lazzyms
Created September 20, 2018 10:05
Show Gist options
  • Save lazzyms/3a1ec6317abfd9005e6d875b255359ff to your computer and use it in GitHub Desktop.
Save lazzyms/3a1ec6317abfd9005e6d875b255359ff to your computer and use it in GitHub Desktop.
Convert Html to pdf using Chrome Headless - php script
<?php
$chrome_path = 'C:\"Program Files (x86)"\Google\Chrome\Application\chrome.exe'; // for windows user
$chrome_path = 'chromium-browser'; // for linux user, first install chromium-browser to linux
$output_file = 'path/to/store/sample.pdf';
$url = 'http://www.google.com';
$command = $chrome_path . " --headless --disable-gpu --enable-logging --print-to-pdf="
. $output_file . " " . $url . " --virtual-time-budget=1000 "; // virtual-time-budget is used for delay loading js
try {
exec($command);
} catch (Exception $ex) {
return $ex;
}
return null;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment