【问题标题】:ERR_INVALID_RESPONSE on Chrome while opening PDF generated through PHP在打开通过 PHP 生成的 PDF 时,Chrome 上的 ERR_INVALID_RESPONSE
【发布时间】:2017-06-07 18:01:39
【问题描述】:

我正在尝试打开由 PHP 使用 html2pdf 动态生成的 PDF。 它在 Firefox 和 Safari 上运行良好。但是在 Chrome 上给出 ERR_INVALID_RESPONSE。 之前一切都运行良好,直到我们将网站更新到 CodeIgniter 3.1.4。 已经到处搜索,没有找到适合我的问题的解决方案。 任何帮助将不胜感激。

function property_pdf_ver2($property_id = FALSE, $tenure_text = FALSE) {
    error_reporting(E_ALL);        
    require_once(APPPATH . 'third_party/html2pdf/html2pdf.class.php');
    $template_pdf = $this->load->view('templates/property-pdf-ver2', $data, TRUE);
    $html2pdf = new HTML2PDF('L', 'A5', 'en', true, 'UTF-8', array(0, 0, 0, 0));
    $html2pdf->setDefaultFont('helvetica');
    $html2pdf->addFont('robotolight', false, getcwd() . '/assets/fonts/robotottf/robotolight.php');
    $html2pdf->addFont('robotomedium', false, getcwd() . '/assets/fonts/robotottf/robotomedium.php');
    $html2pdf->addFont('robotothin', false, getcwd() . '/assets/fonts/robotottf/robotothin.php');
    $html2pdf->WriteHTML($template_pdf);
    $html2pdf->Output('sample.pdf');
    $html2pdf->SetFillColor(0, 128, 190);
}

【问题讨论】:

  • 您能否提供您在 codeigniter 中使用的代码,以便我们为您提供帮助。
  • @timothymarois 我添加了控制器功能来支持我的问题。
  • 这里回答了同样的问题stackoverflow.com/questions/34599266/…
  • @AgniusSteponavičius 我已经看过那篇文章,但没有任何意义。

标签: php codeigniter google-chrome pdf html2pdf


【解决方案1】:

这很奇怪,但经过仔细调试后,我找到了问题的原因。 下面的行阻止了 chrome 加载 PDF。我必须删除它才能使该功能正常工作。

$html2pdf->SetFillColor(0, 128, 190);

感谢大家对我的问题的考虑。

【讨论】:

    猜你喜欢
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-07
    • 1970-01-01
    • 2017-11-26
    • 2013-06-09
    相关资源
    最近更新 更多