使用Mikehaertl的WkHtmlToPdf创建横向PDF

Nee*_*eel 3 php pdf oop orientation wkhtmltopdf

我正在使用mikehaertl的OOP界面通过php使用wkhtmltpdf创建pdf.参考:http://mikehaertl.github.io/phpwkhtmltopdf/

这是我的代码:

<?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());
Run Code Online (Sandbox Code Playgroud)

上面的代码生成pdf但它只创建纵向的所有文件.如何将其更改为横向?当我在网上搜索时,我发现wkhtlktopdf有一个选项(-O landscape)来改变方向,但我不知道如何使用Mikeheart创建的PHP WkHtmlToPdf?

Ale*_*daz 7

您可以通过调用setOptions()所需选项的数组来完成此操作,在这种情况下array('orientation' => 'landscape'),在addPage()调用之前.

$pdf->setOptions(array(
    'orientation' => 'landscape'
));
Run Code Online (Sandbox Code Playgroud)

从这里可以看出:https://github.com/mikehaertl/phpwkhtmltopdf#full-example

您可以将wkhtmltopdf文档中 "全局选项"下的任何其他选项添加到传入的数组中.