使用 DomPDF 创建日志文件
Creating a Log File with DomPDF
我在让 font-awesome 在我的网络服务器上的 DomPDF 文档中工作时遇到问题。然而,同样的 HTML 在使用 eclecticgeek.com 的 DomPDF 调试助手时确实有效。因此,我知道 HTML 没有问题。这是工作代码的 link:
http://eclecticgeek.com/dompdf/debug.php?identifier=d0c3b30ed7fd65fabb5c64dda47decc5
我试图在我的本地网络服务器上填充 DomPDF 的日志文件以帮助隔离问题,但没有为我生成文件。这是我的完整代码,我试图通过 DomPDF 的选项设置日志文件,但我不确定我做的是否正确。
<?php
require_once "sites/all/libraries/dompdf/autoload.inc.php";
use Dompdf\Dompdf;
$HTML = <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Macondo" rel="stylesheet">
<style type="text/css">
.fa {
display: inline;
font-style: normal;
font-variant: normal;
font-weight: normal;
font-size: 14px;
line-height: 1;
font-family: FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
</style>
</head>
<body>
<p><span class="fa fa-envelope"></span> Font awesome doesn't work on my webserver</p>
<p style='font-family: "FontAwesome"'>  </p> <span> this also does not work </span>
<p style='font-family: "Macondo", cursive;'> This font works</p>
</body>
</html>
HTML;
$dompdf = new \Dompdf\Dompdf(array(
'tempDir' => 'sites/test.com/modules/CCPDF/',
'isRemoteEnabled' => true,
'isPhpEnabled' => true,
'isJavascriptEnabled' => true,
'pdfBackend' => "CPDF",
'isHtml5ParserEnabled' => true,
'logOutputFile' => 'sites/test.com/modules/CCPDF/test.log',
'DOMPDF_UNICODE_ENABLED' => true
));
$dompdf->load_html($HTML);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream();
?>
任何人都可以提供如何正确设置 DomPDF 日志文件的示例吗?
这是我在本地调试时使用的 PHP 的片段。
ini_set('display_errors', true);
ini_set('error_log', 'output/tester.err.log');
ini_set('log_errors', true);
error_reporting(E_ALL);
$dompdf_options = array(
'chroot' => '/',
'logOutputFile' => __DIR__ . '/dompdf.log.html',
'isHtml5ParserEnabled' => true,
'debugPng' => false,
'debugKeepTemp' => false,
'debugCss' => false,
'debugLayout' => false,
'debugLayoutLines' => false,
'debugLayoutBlocks' => false,
'debugLayoutInline' => false,
'debugLayoutPaddingBox' => false
);
$_dompdf_show_warnings = true;
$_dompdf_debug = false;
$_DOMPDF_DEBUG_TYPES = [
'page-break' => false
];
$dompdf = new Dompdf\Dompdf($dompdf_options);
echo 'Running with ' , $dompdf->version , "\n";
$_dompdf_warnings = array();
echo 'Rendering '. $test_file . "\n";
$dompdf->load_html_file($test_file);
$dompdf->render();
file_put_contents(__DIR__ . '/' . basename($test_file) . (strtolower($dompdf_options['pdfBackend']) === 'gd' ? '.png' : '.pdf'), $dompdf->output(array('compress'=>0)));
您可以尝试调试设置以获得不同类型的调试信息。
我在让 font-awesome 在我的网络服务器上的 DomPDF 文档中工作时遇到问题。然而,同样的 HTML 在使用 eclecticgeek.com 的 DomPDF 调试助手时确实有效。因此,我知道 HTML 没有问题。这是工作代码的 link:
http://eclecticgeek.com/dompdf/debug.php?identifier=d0c3b30ed7fd65fabb5c64dda47decc5
我试图在我的本地网络服务器上填充 DomPDF 的日志文件以帮助隔离问题,但没有为我生成文件。这是我的完整代码,我试图通过 DomPDF 的选项设置日志文件,但我不确定我做的是否正确。
<?php
require_once "sites/all/libraries/dompdf/autoload.inc.php";
use Dompdf\Dompdf;
$HTML = <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Macondo" rel="stylesheet">
<style type="text/css">
.fa {
display: inline;
font-style: normal;
font-variant: normal;
font-weight: normal;
font-size: 14px;
line-height: 1;
font-family: FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
</style>
</head>
<body>
<p><span class="fa fa-envelope"></span> Font awesome doesn't work on my webserver</p>
<p style='font-family: "FontAwesome"'>  </p> <span> this also does not work </span>
<p style='font-family: "Macondo", cursive;'> This font works</p>
</body>
</html>
HTML;
$dompdf = new \Dompdf\Dompdf(array(
'tempDir' => 'sites/test.com/modules/CCPDF/',
'isRemoteEnabled' => true,
'isPhpEnabled' => true,
'isJavascriptEnabled' => true,
'pdfBackend' => "CPDF",
'isHtml5ParserEnabled' => true,
'logOutputFile' => 'sites/test.com/modules/CCPDF/test.log',
'DOMPDF_UNICODE_ENABLED' => true
));
$dompdf->load_html($HTML);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream();
?>
任何人都可以提供如何正确设置 DomPDF 日志文件的示例吗?
这是我在本地调试时使用的 PHP 的片段。
ini_set('display_errors', true);
ini_set('error_log', 'output/tester.err.log');
ini_set('log_errors', true);
error_reporting(E_ALL);
$dompdf_options = array(
'chroot' => '/',
'logOutputFile' => __DIR__ . '/dompdf.log.html',
'isHtml5ParserEnabled' => true,
'debugPng' => false,
'debugKeepTemp' => false,
'debugCss' => false,
'debugLayout' => false,
'debugLayoutLines' => false,
'debugLayoutBlocks' => false,
'debugLayoutInline' => false,
'debugLayoutPaddingBox' => false
);
$_dompdf_show_warnings = true;
$_dompdf_debug = false;
$_DOMPDF_DEBUG_TYPES = [
'page-break' => false
];
$dompdf = new Dompdf\Dompdf($dompdf_options);
echo 'Running with ' , $dompdf->version , "\n";
$_dompdf_warnings = array();
echo 'Rendering '. $test_file . "\n";
$dompdf->load_html_file($test_file);
$dompdf->render();
file_put_contents(__DIR__ . '/' . basename($test_file) . (strtolower($dompdf_options['pdfBackend']) === 'gd' ? '.png' : '.pdf'), $dompdf->output(array('compress'=>0)));
您可以尝试调试设置以获得不同类型的调试信息。