【问题标题】:How do I enable debug on dompdf library?如何在 dompdf 库上启用调试?
【发布时间】:2018-01-30 17:40:50
【问题描述】:

我正在使用 dompdf 库来输出一些报告。我有一个文件输出,但我有一些奇怪的行为。如何在dompdf 中启用调试报告?

  $dompdf = new Dompdf();

  // something like this
  $dompdf->enableDebug();

  $dompdf->loadHtml($template);
  $dompdf->setBasePath(realpath('./'));
  $dompdf->render();
  $dompdf->stream('note');

【问题讨论】:

  • 您在寻找什么类型的调试报告?
  • 任何调试信息都会有所帮助。我认为主要是布局。
  • 有两种类型的调试:呈现的 PDF 中的视觉和文本。我想这有助于了解您正在尝试调试哪种类型的奇怪行为。

标签: php dompdf


【解决方案1】:

有几个调试选项:debugPng、debugKeepTemp、debugCss、debugLayout、debugLayoutLines、debugLayoutBlocks、debugLayoutInline、debugLayoutPaddingBox。它们可以像这样传递给构造函数:

<?php
require_once 'vendor/autoload.php';

$dompdf = new \Dompdf\Dompdf(array(
    'debugLayout' => true,
));
$html = '<b>BOLD</b>';

$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream("sample.pdf", array("Attachment"=>0));

【讨论】:

  • 我试过了,但没有得到调试结果。信息打印到哪里?
  • 它在 PDF 中为布局元素的边框添加线条。
【解决方案2】:

BrianS这样设置全局变量:

global $_dompdf_warnings;
$_dompdf_warnings = array();
global $_dompdf_show_warnings;
$_dompdf_show_warnings = true;

然后,不要将 pdf 流式传输到浏览器,而是转储警告数组:

header('Content-type: text/plain');
var_dump($_dompdf_warnings);
die();

【讨论】:

    【解决方案3】:

    如果您想进行一些文本调试,请尝试在使用 Dompdf 之前设置以下全局变量:

    global $_dompdf_warnings = array();
    global $_dompdf_show_warnings = true;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多