2016-12-08 12:23

(内联)PHP in domPDF 7.0


I switched from TCPDF to domPDF because it seems more convenient to handle when creating invoices from html to pdf (I am rather a low pro on PHP :)). Now that I created the html file as a PDF file I recognized it does not output any PHP in the PDF - since the data from my sql databanks should fill the PDF it is kinda a problem.

I saw that you can enable PHP in the options.php included in the src-folder and I tried to do like it is written in the manual (and also tried various other code lines) but it just doesn't want to work:

$root = realpath($_SERVER["DOCUMENT_ROOT"]);

require_once ("$root/../xxx/dompdf/autoload.inc.php");

use Dompdf\Dompdf;
use Dompdf\Options;

$options = new Options();
$dompdf = new Dompdf($options);


$dompdf->setPaper('A4', 'portrait');



The PDF is shown but without the input from any PHP code.

If someone would be so kind, I would also be interested in knowing why and in how far enabling PHP is a security risk since I actually want to use that for my business. Would it be more advisable to wrap it all up in the main php file without loading external html and css files?

Thanks a lot in advance!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douou0977 douou0977 5年前

    You could do something like this (not tested the code). Replace



    include 'testdomhtml.php';
    $output = ob_get_clean();

    More options How to execute and get content of a .php file in a variable?

    点赞 评论 复制链接分享
  • dscqrkvr9562034621 dscqrkvr9562034621 5年前

    Your file_get_contents("testdomhtml.php") will get actual content of file and will not execute any code inside it. Instead make it web accessible and pass URL to this page:

    点赞 评论 复制链接分享