TKA
TKA

Reputation: 128

DOMPDF - PHP-HTML to PDF conversion?

I have a php file of which I want to generate a PDF using dompdf, I have tried it with the code below but I can't get the html of the file from php, any idea on how to get the html elements from php file?

    <?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");
        }
    ?>

EDIT: It now gives an error:

Fatal Error: Maximum execution time of 30 seconds exceeded in .../

Upvotes: 0

Views: 3094

Answers (1)

Tom Metcalfe
Tom Metcalfe

Reputation: 308

Not sure how much this matters but your html closing tag is actually just another open html tag. Try closing it and changing your code to the following :

 <?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");
        }
    ?>

Upvotes: 1

Related Questions