【问题标题】:wkhtmltopdf hangs at 10% when executed via PHP but runs successfully via command linewkhtmltopdf 通过 PHP 执行时挂起 10% 但通过命令行成功运行
【发布时间】:2014-12-02 05:41:39
【问题描述】:

我使用这里描述的 phpwkhtmltopdf How do I get WKHTMLTOPDF to execute via PHP?

将html转换为pdf

set_time_limit (0);

require_once __DIR__.'/vendor/autoload.php';

use mikehaertl\wkhtmlto\Pdf; 

$pdf = new Pdf; 

$pdf->addPage('<html><h1>PDF creation successfull</h1></html>');

$pdf->send('test.pdf');
  if (!$pdf->send('test.pdf')) {
          throw new Exception('Could not create PDF: '.$pdf->getError());
      }

当我运行它时,我得到以下错误

致命错误:未捕获的异常 'Exception' 带有消息 'Could not 创建 PDF:加载页面 (1/6) [> ] 0% [======> ] 10% ' in /home/kpninfotech/public_html/pdfbin/convert.php:30 堆栈跟踪:#0 {main} 在 /home/kpninfotech/public_html/pdfbin/convert.php 上抛出 第 30 行

我也尝试从 php 运行 exec 命令

   error_reporting(E_ALL);
    ini_set('display_errors', '1');
    $cmd = "/usr/bin/wkhtmltopdf http://www.kpninfotech.com test.pdf 2>&1";
    echo $t = exec($cmd);
    exit();

我也遇到同样的错误

[>] 0% [======>] 10%

但是通过 ssh 执行 pdf 转换运行成功

但是我无法通过 PHP 执行,我该如何通过 PHP 执行呢?

我有运行 centos 6.5 的 VPS 服务器,wkhtmltopdf 版本 0.12.1(带有补丁的 qt)

【问题讨论】:

  • 看起来您的 php 用户(apache / www / 等)没有写权限。您可以更改要写入 php 用户的目录的所有权。
  • 服务器可以创建其他文件没有错误kpninfotech.com/pdfbin/test1.php,执行来自stackoverflow.com/questions/5560373/…的代码
  • 暂时把你文件的权限改成777看看会发生什么。
  • 我也面临同样的问题。它通过 SSH 终端运行,但无法通过 php 的 exec 命令执行。
  • 这肯定是你的PHP配置有问题,当我升级到更好的VPS服务器时,我解决了这个问题。如果您有 WHM 访问权限,请将此包设置为使用无限资源。它可能会修复它

标签: php apache pdf centos wkhtmltopdf


【解决方案1】:

我解决了这个问题设置选项disable-javascript

试试这个。

use mikehaertl\wkhtmlto\Pdf; 

$pdf = new Pdf(array('disable-javascript')); 

$pdf->addPage('<html><h1>PDF creation successfull</h1></html>');

$pdf->send('test.pdf');
if (!$pdf->send('test.pdf')) {
  throw new Exception('Could not create PDF: '.$pdf->getError());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 2011-11-10
    • 2012-01-21
    相关资源
    最近更新 更多