0

我有一个 php 文件,我想使用 dompdf 生成一个 PDF,我已经尝试使用下面的代码,但我无法从 php 获取文件的 html,关于如何从 php 文件中获取 html 元素的任何想法?

    <?php
    require_once("dompdf/dompdf_config.inc.php");
    ob_start();        
    ?>
    <html>
     <body>
     <?php
         //Code for a colored table
     ?>
     <form method=post action=#><input type=submit name=submit id=submit value="Create PDF"></form>
     </body>
    <html>

    <?php
        if((isset($_POST['submit'])))
        {
            $html = ob_get_contents(); 
                ob_end_flush();
            $dompdf = new DOMPDF();
            $dompdf->load_html($html);
            $dompdf->render();
            $dompdf->stream("Time Table.pdf");
        }
    ?>

编辑: 它现在给出一个错误:

致命错误:超过 30 秒的最大执行时间.../

4

1 回答 1

1

不确定这有多重要,但您的 html 结束标记实际上只是另一个打开的 html 标记。尝试关闭它并将您的代码更改为以下内容:

 <?php
    require_once("dompdf/dompdf_config.inc.php");
    ob_start();        
    ?>
    <html>
     <body>
     <?php
         //Code for a colored table
     ?>
     <form method=post action=#><input type=submit name=submit id=submit value="Create PDF"></form>
     </body>
    </html>

    <?php
        if((isset($_POST['submit'])))
        {
            $html = ob_get_contents(); 
                ob_end_flush();
            $dompdf = new DOMPDF();
            $dompdf->load_html($html);
            $dompdf->render();
            $dompdf->stream("Time Table.pdf");
        }
    ?>
于 2013-07-30T12:49:07.590 回答