Created
September 20, 2018 10:05
-
-
Save lazzyms/3a1ec6317abfd9005e6d875b255359ff to your computer and use it in GitHub Desktop.
Convert Html to pdf using Chrome Headless - php script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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