本文介绍了使用wkhtmltopdf设置横向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How I can change the orientation of my pdf file which is generated with Wkhtmltopdf. I invoke it in PHP like following:

$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包含我的整个页面,这将打开一个临时文件.

$html contains my whole page in html, and this opens a temporary file.

这将生成纵向的.pdf.我知道wkhtlktopdf有一个选项-O landscape可以更改方向,但是我不知道该在何处以及如何在PHP脚本中编写此内容.我正在使用Windows 7.

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.

推荐答案

选项-O landscape可以解决问题.

随便

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");

这篇关于使用wkhtmltopdf设置横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 22:31