如何让 WKHTMLTOPDF 通过 PHP 执行?
2022-08-30 10:17:01
这在一定程度上已经被问过了,但没有解决方案或公认的答案,我想尝试在我的问题中更全面,所以:
我正在尝试在共享服务器上通过PHP启动并运行WKHTMLTOPDF(在本例中是MediaTemple(gs))。根据主机的说法,没有理由这不起作用,实际上它是通过SSH工作的。所以。。。
我尝试过各种各样的事情,最基本的什么都不做,只是默默地失败了:
exec("/path/to/binary/wkhtmltopdf http://www.google.com pdf1.pdf");
完整的PHP绑定以及以下内容给了我错误,尽管我最好地谷歌搜索,但我无法弄清楚:
叫:
$html = file_get_contents("http://www.google.com");
$pdf = new WKPDF();
$pdf->set_html($html);
$pdf->render();
$pdf->output(WKPDF::$PDF_EMBEDDED,'sample.pdf');
- 资料来源:WKHTMLTOPDF on Google Code
错误:
Fatal error: Uncaught exception 'Exception' with message 'WKPDF didn't return
any data. <pre>Loading pages (1/6) [> ] 0% [======> ] 10% terminate called
after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc </pre>'
in /path/to/wkhtmltopdf.php:206 Stack trace: #0 /path/to/index.php(8):
WKPDF->render() #1 {main} thrown in /path/to/wkhtmltopdf.php on line 206
一旦我得到这个(下面是一个摘录,因为我现在无法复制它):
Qt Concurrent has caught an exception thrown from a worker thread. This is not
supported, exceptions thrown in worker threads must be caught before
control returns to Qt Concurrent.
我也尝试了其他一些选项,但结果相同;没有 PDF。那么我现在该怎么办,我该如何找出问题所在?我的PHP水平是基本的,但我会尽力而为。