Damilare Binutu Damilare Binutu - 1 year ago 149
HTML Question

Converting Dynamic HTML TO PDF using html2pdf

The pages I want to convert are generated dynamically via PHP from a MySQL database. In other words the information on a page depends on the Id of the chosen object. So I would normally have a URL like this


I am using
and so far I am unable to perform the conversion. When I pass
directly like this

// get the HTML
$content = ob_get_clean();`

I get these errors:

Warning: include(renal_prescRequest_review.php?id=2) [function.include
]: failed to open stream: No such file or directory
on line5

Warning: include(renal_prescRequest_review.php?id=2)
[function.include]: failed to open stream: No such file or directory
in /home/renalmed/public_html/testing/test/renal_prescRequest_pdf.php
on line5

Warning: include() [function.include]: Failed opening
'renal_prescRequest_review.php?id=2' for
in/home/renalme/public_html/testing/test/renal_prescRequest_pdf.php on

The fascinating thing is that these errors are thrown on the PDF document where the actual HTML is supposed to be displayed. I have been on this for quite a while now. Please help.

Answer Source

You can't include a query string on the include file.

One solution on this is to transfer the codes of renal_prescRequest_review.php in the file where you want to convert html to pdf.

Below is the sample code.

 * HTML2PDF Librairy - example
 * HTML => PDF convertor
 * distributed under the LGPL License
 * @author      Laurent MINGUET <webmaster@html2pdf.fr>
 * isset($_GET['vuehtml']) is not mandatory
 * it allow to display the result in the HTML format
// get the HTML
// database connection here
require_once ( 'database-connection.php' );
// get the id
$id = $_GET['id'];
// Retrieve record from database
// query code here
<page backleft="0mm" backtop="0mm" backright="0mm" backbottom="0mm">    
    ID: <?php echo $id;?>
    <!--other html and php codes here.-->
$content = ob_get_clean();
// convert to PDF
    $html2pdf = new HTML2PDF('P', array(200,300), 'en', true, 'UTF-8', array(0, 0, 0, 0));
    //$html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', 0);
    //$html2pdf->Output('test.pdf','D'); // force download pdf
    $html2pdf->Output('test.pdf'); // display only
catch(HTML2PDF_exception $e) {
    echo $e;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download