Question

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

renal_prescRequest_review.php?id=4

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

// get the HTML
ob_start();
include("renal_clinicalTrial_review.php?id=2");
$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 in/home/renalmed/public_html/testing/test/renal_prescRequest_pdf.php 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 inclusion(include_path='.:/usr/lib/php:/usr/local/lib/php') in/home/renalme/public_html/testing/test/renal_prescRequest_pdf.php on line5.

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.

Was it helpful?

Solution

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.

<?php
/**
 * 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
ob_start();
// 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.-->
</page>
<?php
$content = ob_get_clean();
// convert to PDF
require_once('../html2pdf/html2pdf.class.php');
try
{
    $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->pdf->SetDisplayMode('fullpage');
    $html2pdf->writeHTML($content);
    //$html2pdf->Output('test.pdf','D'); // force download pdf
    $html2pdf->Output('test.pdf'); // display only
}
catch(HTML2PDF_exception $e) {
    echo $e;
    exit;
}

OTHER TIPS

I'm not sure you can use get variables in include. Use an url with file_get_contents function. Or remove the get variable id and assign it before the include, detect it with an isset within the included script.

Warning: include(renal_prescRequest_review.php?id=2)

You can't include files like that. You're specifying a query string within the include statement, where PHP is simply expecting a path. So PHP is expecting to find a file called renal_prescRequest_review.php?id=2 (in other words, it's not looking for renal_prescRequest_review.php). Your PHP should look like

include('renal_prescRequest_review.php');

You can use session on this and remove the query string on the include file

session_start();
// get the HTML
ob_start();
$_SESSION['id'] = 2;
include("renal_clinicalTrial_review.php");
$content = ob_get_clean();

In the renal_clinicalTrial_review.php, put session_start(); and you can use now the session.

You can not include the file like this :

include("renal_clinicalTrial_review.php?id=2");

You should do it like this :

include("renal_clinicalTrial_review.php");

The parameter is then passed to the calling page.

For example, if your code is saved as test.php, then call it like this:

test.php?id=2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top