【发布时间】:2012-05-06 00:34:11
【问题描述】:
这是我的代码:
$url = escapeshellarg("http://www.mysite.com");
$command = shell_exec("xvfb-run -a -s '-screen 0 640x480x16' wkhtmltopdf --dpi 300 --page-size A4 $url /srv/www/mysite/public_html/tmp_pdf.pdf");
$str = file_get_contents("/srv/www/mysite/public_html/tmp_pdf.pdf");
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($str));
header('Content-Disposition: inline; filename="pdf.pdf"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');
die($str);
在我的 bash shell(使用 Debian)中,命令
shell_exec("xvfb-run -a -s '-screen 0 640x480x16' wkhtmltopdf --dpi 300 --page-size A4 html://www.mysite.com /srv/www/mysite/public_html/tmp_pdf.pdf
工作,它会在所需的位置生成一个 pdf,但是当我在 php 中执行命令时,什么都没有创建,我返回到一个空的 pdf 文件(因为它不存在)。 有人可以帮我找出问题所在吗?
【问题讨论】:
-
我希望 html:// 协议存在,否则您可能想尝试 http:// .. 此外,要确保 URL 中没有其他字符在 shell_exec/ 中被解释bash,在将其作为参数传递之前,在 url php.net/manual/en/function.escapeshellarg.php 上使用 escapeshellarg()。干杯
标签: php bash pdf pdf-generation wkhtmltopdf