php 使用 wkhtmltopdf 设置横向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16833528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use wkhtmltopdf to set landscape orientation
提问by Daykeras
How I can change the orientation of my pdf
file which is generated with Wkhtmltopdf
. I invoke it in PHP like following:
如何更改pdf
使用Wkhtmltopdf
. 我在 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
contains my whole page in html, and this opens a temporary file.
$html
包含我在 html 中的整个页面,这会打开一个临时文件。
This generates a .pdf
in portrait orientation. I know wkhtlktopdf has an option -O landscape
to change orientation, but I don't know where and how I can write this in my PHP script. I'm using Windows 7.
这会生成.pdf
纵向的 。我知道 wkhtlktopdf 有一个-O landscape
更改方向的选项,但我不知道在哪里以及如何在我的 PHP 脚本中编写它。我正在使用 Windows 7。
回答by Mantas
Option -O landscape
will do the trick.
选项-O landscape
可以解决问题。
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");
回答by DamienB
I think this is also worth mentioning here:
我认为这里也值得一提:
I was having trouble with this too but I had set --orientation "Landscape" and had also set the --page-height '210mm' and --page-width '297mm'
我也遇到了这个问题,但我已经设置了 --orientation "Landscape" 并且还设置了 --page-height '210mm' 和 --page-width '297mm'
My pdf's kept coming out in Portrait, very frustrating.
我的 pdf 不断出现在肖像中,非常令人沮丧。
I was being too explicit. Taking out the page-height and page-width options resolved the issue for me
我说得太露骨了。取出页面高度和页面宽度选项为我解决了这个问题