指向我们网络服务器上发票的示例链接:
http://billing/view/invoice?id=1
这将在浏览器中显示发票。
为了将其另存为 PDF,我尝试:
<?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);
?>
这将显示空白页,没有发票或 PDF。
如果我改变
$invoice = file_get_contents_curl('view/invoice?id=1');
$dompdf->load_html($invoice);
自
$invoice = "Hello";
$dompdf->load_html($invoice);
然后它显示一个包含"Hello"的 PDF,因此捕获动态 PHP 发票似乎是一个问题。
错误报告显示:
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
尝试在以下位置添加完整的网址:
$invoice = file_get_contents_curl('http://...view/invoice?id=1');