Php 使用wkhtmltopdf设置横向方向

Php 使用wkhtmltopdf设置横向方向,php,pdf,wkhtmltopdf,Php,Pdf,Wkhtmltopdf,如何更改使用Wkhtmltopdf生成的pdf文件的方向。我在PHP中调用它,如下所示: $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.h

如何更改使用
Wkhtmltopdf
生成的
pdf
文件的方向。我在PHP中调用它,如下所示:

$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");
$html
以html格式包含我的整个页面,这将打开一个临时文件


这将生成纵向的
.pdf
。我知道wkhtlktopdf有一个选项
-O横向
来改变方向,但我不知道在我的PHP脚本中可以在哪里以及如何编写它。我使用的是Windows 7。

选项
-O横向
就可以了

恰奇

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

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

我认为这也值得一提:

我在这方面也遇到了问题,但我已经设置了方向“横向”,并且还设置了页面高度“210mm”和页面宽度“297mm”

我的pdf一直以肖像的形式出现,非常令人沮丧


我太露骨了。去掉页面高度和页面宽度选项解决了我的问题

是的,这真的很容易!谢谢。在wkhtmltopdf命令之后传递两个标志
-O横向
,例如:
wkhtmltopdf-O横向foobar.html foobar.pdf
小逻辑陷阱。如果你的宽度大于你的高度,那么横向会给你一个看起来像肖像的方向(因为它交换宽度和高度)。