Skip to content

Instantly share code, notes, and snippets.

@alpenzoo
Created December 11, 2019 13:11
Show Gist options
  • Save alpenzoo/b3d4b2ae144d00fe2b8d442d03d7fd50 to your computer and use it in GitHub Desktop.
Save alpenzoo/b3d4b2ae144d00fe2b8d442d03d7fd50 to your computer and use it in GitHub Desktop.
<?php
$opt = array(
"--zoom"=>'1',
"--disable-smart-shrinking"=>'',
"--page-size"=>'A4',
"--orientation"=>'Landscape',
"--margin-bottom"=>'0',
"--margin-top"=>'0',
"--margin-left"=>'0',
"--margin-right"=>'0'
);
$args = array(
"url"=>'your url',
"file"=>'output.pdf'
);
$tmpFile = "/tmp/".$args['file'];
$optStr = '';
foreach ($opt as $key => $value) {
$optStr .= ' '.$key.' '.$value;
}
$cmdLine = '/usr/bin/wkhtmltopdf'.$optStr.' '.$args['url'].' '.$tmpFile;
//die($cmdLine);
$output = shell_exec($cmdLine);
if (file_exists($tmpFile)) {
header('Content-Disposition: inline; filename="'.basename($tmpFile).'"');
header('Content-Type: application/pdf');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($tmpFile));
readfile($tmpFile);
unlink($tmpFile);
exit;
}else{
die("File not found.");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment