我知道有很多关于这个问题的帖子.但是有人可以帮我设置这个
http://www.rustyparts.com/pdf.php脚本来处理我的本地主机.我只花了整整一周就这个问题.我有下载imagemagic,ghostscript,activeperl,…,一切,但仍然不能使简单的例子工作.
通过系统调用使用
wkhtmltopdf.有关安装帮助,请参见
How to install wkhtmltopdf on a linux based (shared hosting) web server.
wkhtmltopdf is a command line program
which permits to create a pdf from an
url,a local html file or stdin. It
produces a pdf like rendred with the
WebKit engine.
请参阅本页here中的示例.
在Ubuntu上测试的PHP代码(你需要将/ tmp /更改为Windows上的临时目录):
$url = 'http://www.google.com'; $pdffile = tempnam('/tmp/','wkhtmltopdf_'); $handle = popen("wkhtmltopdf $url $pdffile 2>&1","r"); while (!feof($handle)) fread($handle,4096); pclose($handle); header('Content-type: application/pdf'); $file = fopen($pdffile,"r"); while(!feof($file)) print fread($file,4096); unlink($pdffile);
还有php bindings,它不需要自己使用系统调用,这是一个更简单(和更安全!)的选项.
try { $wkhtmltopdf = new Core_Wkhtmltopdf(array('path' => APPLICATION_PATH . '/../public/uploads/')); $wkhtmltopdf->setTitle("Title"); $wkhtmltopdf->setHtml("Content"); $wkhtmltopdf->output(Wkhtmltopdf::MODE_DOWNLOAD,"file.pdf"); } catch (Exception $e) { echo $e->getMessage(); }