dtqie02844 2012-06-12 10:54 采纳率: 0%
浏览 578

使用Wkhtmltopdf从PHP中的html生成pdf

On my windows with xamp local server I follow pdf generator from html step 1 & 2 (wkhtmltopdf http://www.test.com test.pdf) goes fine but step 3

3. In php you should execute the tool using shell_exec:

shell_exec("/usr/local/bin/wkhtmltopdf-i386 http://test.com test.pdf");
//for Linux 32 bits operating system
//for Linux 64 bits operating system use wkhtmltopdf-amd64
//for windows just put the path of the exe file.
$allfile = file_get_contents("test.pdf");
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($allfile));
header('Content-Disposition: inline; filename="test.pdf"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');

does not do any thing... :(

I installed at e drive and used:

exec("e:\wkhtmltopdf\wkhtmltopdf.exe http://www.google.com/ test.pdf");

Actually I creates PDF correctly but does not send output to browser.. any idea what I had missed ...?

  • 写回答

1条回答 默认 最新

  • doucan4873 2012-08-09 13:53
    关注

    I'm guessing but the issue might be file locations. Does file_get_contents actually find the file?

    I'm not very sure where the pdf file gets generated during the exec, try to use full paths for both the output pdf location and the file_get_contents location, they might not be correct by default. Maby even check somehow that the files exist and what folder are they both using (I cant remember how to do this in PHP :))

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序