This is an archived forum post. The information may be outdated. Contact us if you have any questions.

How to export php file to pdf?

kplee wrote on 2015-06-24:
Dear All,
I have a example.php file and the code inside are:

<div class="tmp_data">My data is: <?php print $data;?></div>

when I export it using:
require 'pdfcrowd.php';

// create an API client instance
$client = new Pdfcrowd("***", "***");

// convert a web page and store the generated PDF into a $pdf variable
//$pdf = $client->convertURI('');
$pdf = $client->convertFile("view_form_data.php");
// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: max-age=0");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"google_com.pdf\"");

// send the generated PDF
echo $pdf;
catch(PdfcrowdException $why)
echo "Pdfcrowd Error: " . $why;

The PDF shown "My data is: <?php print $data;?>", not "My data is: 123".....

How can I export the correct data to pdf??

Please help!

Thank you.
support wrote on 2015-06-24:

You can't pass a PHP script to the convertFile() function. convertFile() can convert only HTML files.
You need to run your PHP script on a server and then pass its URL to the convertURI() function.
kplee wrote on 2015-06-24:
Thank you~I really made a stupid mistake!! Haha!