【发布时间】:2011-03-14 10:22:08
【问题描述】:
我对 DOMPDF 有疑问。我正在运行 PHP 5.3.3 并拥有最新的 DOMPDF 0.6.0 beta2。
我已经创建了这个 HTML 模板:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Printed document</title>
</head>
<body>
<script type="text/php">
echo "test";
if ( isset($pdf) ) {
echo $PAGE_NUM;
}
</script>
</body>
</html>
这个文件用来渲染 PDF:
<?php
require_once("dompdf/dompdf_config.inc.php");
$templateFile = 'template.html';
$content = file_get_contents($templateFile);
if ($content !== false) {
$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->render();
$dompdf->stream("test.pdf");
}
?>
在 dompdf_config.inc.php 中,我已将 DOMPDF_ENABLE_PHP 设置为 true,但在渲染的 PDF 中仍然显示测试字符串或页数。为什么?
我在这里压缩了我的小例子: http://uploads.dennismadsen.com/pdf.zip
如果您需要更多信息,请告诉我。
【问题讨论】:
-
好吧,看来第二遍不能回显任何变量——而只能使用 PDF 对象绘制文本。不知道我必须插入 PAGE_NUM 的位置,因为它不是页眉或页脚的一部分 - 因此我无法使用绘图。有什么方法可以在文档的自定义位置插入变量?