简体   繁体   中英

Creating Landscape PDF using WkHtmlToPdf by Mikehaertl

I am using mikehaertl's OOP interface to create pdf using wkhtmltpdf via php. Ref: http://mikehaertl.github.io/phpwkhtmltopdf/

This is my code:

<?php
require_once('../WkHtmlToPdf.php');

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

// Add a HTML file, a HTML string or a page from a URL
$pdf->addPage('page.html');

if(!$pdf->send())
    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.

$pdf->setOptions(array(
    'orientation' => 'landscape'
));

As can be seen here: https://github.com/mikehaertl/phpwkhtmltopdf#full-example

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM