1

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
  • Whenever you get a blank page (the "white screen of death") in PHP when some output is otherwise expected, ensure that you have error reporting turned all the way up and displaying on screen. Always when developing code, `error_reporting(E_ALL); ini_set('display_errors', 1);` at the top of your script, though it would be easier to watch the server's error log for a script which is sending content with a `Content-Type` other than text. – Michael Berkowski Mar 16 '15 at 14:18

1 Answers1

2

Try adding full url in:

$invoice = file_get_contents_curl('http://...view/invoice?id=1');
Ali Arshad
  • 436
  • 2
  • 12
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Maxim Mar 16 '15 at 14:39
  • 2
    I think this is the actual issue... because he is trying to curl **view/invoice?id=1** curl is obviously returning blank data... he has to provide full url to curl to get the data... 2ndly when I posted this my rep was below 50, so this was the only option I had :) – Ali Arshad Mar 16 '15 at 14:45
  • @AliArshad I changed it but now I get a PDF of the login screen ;> –  Mar 16 '15 at 14:52
  • 1
    So this confirms that issue was of http... now if the invoices are not public you will defiantly see the login screen... work around would be to copy the code of order.php and reuse it here...# – Ali Arshad Mar 16 '15 at 14:58
  • In addition to the reproducing the code in the invoice you could pass authentication credentials via curl. I've not done this myself, but you can find that info on SO (e.g. [here](http://stackoverflow.com/q/6997665/264628) and [here](http://stackoverflow.com/q/12885538/264628)). – BrianS Mar 17 '15 at 00:41