php - 内联 php 脚本变量在 DOMPDF 中不起作用

标签 php dompdf html-to-pdf

当我生成 pdf 时,内联 php 脚本没有执行,只有 html 部分打印在 pdf 上。我已经设置了 $isPhpEnabled =True 。

<?php
// include autoloader
require_once 'dompdf/autoload.inc.php';

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$abc="This is the php text";
$html = <<<'ENDHTML'
<html>
<head>
<style>
h1{color:#555555;width:100%;border-bottom:2px solid powderblue;}
</style>
</head>
 <body>
  <h1 >Name : <script type="text/php"> echo $abc; </script></h1>
 </body>
</html>
ENDHTML;
$dompdf->loadHtml($html);

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
?>

最佳答案

尝试

<?php
// include autoloader
require_once 'dompdf/autoload.inc.php';

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$abc="This is the php text";
$html = "
<html>
<head>
<style>
h1{color:#555555;width:100%;border-bottom:2px solid powderblue;}
</style>
</head>
 <body>
  <h1 >Name : $abc</h1>
 </body>
</html>
";
$dompdf->loadHtml($html);

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
?>

关于php - 内联 php 脚本变量在 DOMPDF 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46666690/

相关文章:

php - Magento 2 : How to run CLI command from another CLI command class?

php - 在 Ubuntu Server 12.04 上编译 libvirt-php 时出错

php - 如何使用dompdf设置pdf的自定义宽度和高度?

c# - 使用 ExpertPDF 从 HTML 生成的 PDF 的质量差异

php - Yii HTML2PDF (ePdf) Impossible de charger l'image/images/big-logo.png

javascript - 如何为 Bootstraps 模态传递数据

PHP检查数据库中是否存在某些内容

html - DOMPDF - 无法让内部分页工作

html - Dompdf 将 html Bootstrap 代码打印为 col-sm-x 而不是 col-lg-x

java.lang.NoClassDefFoundError : com/itextpdf/kernel/counter/event/IMetaInfo 错误