Daykeras Daykeras - 3 months ago 26
PHP Question

wkhtmltopdf and landscape orientation

I simply would like to know how I can change the orientation of my pdf which is generated with Wkhtmltopdf. I use it in php like following:




$file=fopen("tmp/html/pdfTmp_$numRand.html","w") or exit("Unable to open file!");
fwrite($file, $html);
fclose($file);
exec("..\library\wkhtmltopdf\wkhtmltopdf tmp/html/pdfTmp_$numRand.html tmp/pdf/pdfTmp_$numRand.pdf");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=".$nom."_".$residence.".pdf");
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("tmp/pdf/pdfTmp_$numRand.pdf"));
ob_clean();
flush();
readfile("tmp/pdf/pdfTmp_$numRand.pdf");
?></pre>



$html contains my whole page in html, and this opens a temporary file.

This generates a .pdf, but in portrait. I know wkhtlktopdf has an option (-O landscape) to change the orientation, but I don't know where and how I can write this in my action controller, and I don't want to use a command-line. I'm working on Windows 7. Thanks for helping me.

Answer

Option -O landscape will do the trick.

Just chage

exec("..\library\wkhtmltopdf\wkhtmltopdf tmp/html/pdfTmp_$numRand.html tmp/pdf/pdfTmp_$numRand.pdf");

to something like

exec("..\library\wkhtmltopdf\wkhtmltopdf -O landscape tmp/html/pdfTmp_$numRand.html tmp/pdf/pdfTmp_$numRand.pdf");
Comments