An example link to an invoice on our web server:
http://billing/view/invoice?id=1
This shows the invoice in the browser.
To save it as PDF I tried:
<?php
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$invoice = file_get_contents_curl('view/invoice?id=1');
$dompdf->load_html($invoice);
$dompdf->set_paper('a4');
$dompdf->render();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
?>
This shows a blank page, no invoice or PDF.
If I change
$invoice = file_get_contents_curl('view/invoice?id=1');
$dompdf->load_html($invoice);
to
$invoice = "Hello";
$dompdf->load_html($invoice);
then it shows a PDF containing "Hello", so it seems is a problem capturing the dynamic PHP invoice.
Error reporting shows:
Warning: file_get_contents(view/order.php?id=1432923): failed to open stream: No error in C:\inetpub\wwwroot\billing\test.php on line 6