Neel Neel - 11 months ago 247
PHP Question

Creating Landscape PDF using WkHtmlToPdf by Mikehaertl

I am using mikehaertl's OOP interface to create pdf using wkhtmltpdf via php. Ref:

This is my code:


$pdf = new WkHtmlToPdf(array(
// Use `wkhtmltopdf-i386` or `wkhtmltopdf-amd64`
'bin' => 'C:\Users\me\Documents\EasyPHP-\www\wkhtmltopdf\wkhtmltopdf.exe'

// Add a HTML file, a HTML string or a page from a URL

throw new Exception('Could not create PDF: '.$pdf->getError());

The above code generates the pdf but it only creates all files in the portrait orientation. How do I change it to landscape orientation? When I searching the web, I found that wkhtlktopdf has an option (-O landscape) to change the orientation but I dont know how to use it with PHP WkHtmlToPdf created by Mikeheart?


You can do this by calling setOptions() with an array of your desired options, in this case array('orientation' => 'landscape') before the addPage() call.

    'orientation' => 'landscape'

As can be seen here:

You can add any other options that can be found under "Global Options" in the wkhtmltopdf documentation, to the array you pass in.