I'm using WKHTMLTOPDF for a client. My PHP is quite rough... The problem is, my arguments aren't working, and in the below example they could be wrong, but none are working... such as zoom, page-size, etc. So for example, in the switch statement, you can see the Building type. I want this to output as a standard US Letter type. --page-size A, or is it --page-size "A", or --page-size "Letter"? But regardless, I'm not passing the arguments properly, because no matter what I change, (i.e. --zoom .10) for testing, nothing changes. Any help is appreciated!
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
try {
$mydir = getcwd();
// Figure out the URL
$url = $_GET['url'];
$url = str_replace(';', ' ', $url);
// Figure out the mode
$mode = isset($_GET['mode']) ? $_GET['mode'] : 'standard';
// Figure out the mode
$name = isset($_GET['name']) ? '-' . $_GET['name'] . '-' : '';
// Generate GUID filename
$file = $mydir . '\\' . uniqid('', true) . '.pdf';
// Build arguments
$args = '
--load-error-handling ignore
';
switch($mode) {
case 'Site';
$args .= ' --title "Site Report"';
$filename = 'Site-Report' . $name . '.pdf';
break;
case 'Building';
$args .= ' --title "Building Report" --page-size "A"';
$filename = 'Building-Report' . $name . '.pdf';
break;
case 'standard';
default;
$args .= ' --title "Development Report" --zoom .55';
$filename = 'Development-Web-Report.pdf';
break;
}
// Build the command
putenv("path=" . getenv("path") . ';"C:\Program Files (x86)\wkhtmltopdf"');
$cmd = escapeshellcmd('CMD /c wkhtmltopdf ' . $url . ' ' . $file);
$com = new COM("WScript.Shell");
$shell = $com->Exec($cmd);
$shell->StdErr->ReadAll;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=' . $filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
unlink($file);
exit;
}
} catch (Exception $e) {
echo $e->getMessage();
}
?>