5

dompdf is not able to generate a pdf from a page of my website. However, I've saved the page and uploaded it as simple static html file, and it worked!

So, I don't know if the issue is with the url, or something else.. this is the error I get:

Warning: require_once(/home/o110334/public_html/dompdf/include/firephp.cls.php) [function.require-once]: failed to open stream: No such file or directory in /home/o110334/public_html/dompdf/dompdf_config.inc.php on line 194

Fatal error: require_once() [function.require]: Failed opening required '/home/o110334/public_html/dompdf/include/firephp.cls.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/o110334/public_html/dompdf/dompdf_config.inc.php on line 194

This is the code:

$file = "admin/store/orders/45/invoice/print"; // doesn't work
//$file = "invoice_sample2.html"; //it works (same web page, but stored in a html file)

$dompdf = new DOMPDF();
$dompdf->load_html_file($file);
$dompdf->render();
$dompdf->stream("sample.pdf");
Rup
  • 33,765
  • 9
  • 83
  • 112
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
  • Are you using some kind of framework? I ask because of the file path, which seems like the kind of friendly URL that might be used by a framework. If so, method #1 specified by Wrikken is the option you want to use. DOMPDF assumes a local file system path unless you specify a full URL (e.g. http://example.com/admin/store/orders/45/invoice/print). The framework won't process the file unless you go through the web server. – BrianS Jul 15 '10 at 18:31

1 Answers1

14

DOMPDF is trying all kinds of stuff/eval's when running local, you're better of trying:

1) the (granted, long way trip) of requesting the HTML by http:

$dompdf->load_html_file('http://yourdomain.ext/'.$file);

2) Don't let DOMPDF eval but use output buffering itself, and let DOMPDF load the resulting string of HTML.

<?php
    ob_start();
    //be sure this file exists, and works outside of web context etc.)
    require("admin/store/orders/45/invoice/print");
    $dompdf = new DOMPDF();
    $dompdf->load_html(ob_get_clean());
    $dompdf->render();
?>
Wrikken
  • 69,272
  • 8
  • 97
  • 136
  • I've updated my question. The same page is correctly rendered if loaded from a static html file (even locally). – aneuryzm Jul 14 '10 at 16:33
  • 1
    That's what I said. i said do NOT let DOMPDF run your php. – Wrikken Jul 14 '10 at 16:46
  • 1
    Method #1 coded to be more portable $file = "/admin/store/orders/45/invoice/print"; $dompdf->load_html_file('http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).$file); – BrianS Jul 15 '10 at 18:37
  • @BrianS: `PHP_SELF` is not often to the point, certainly not with url rewriting, standard landing script etc. a `$_SERVER['REQUEST_URI']` would me more portable, but I really dislike (1), I'd go for (2) if possible. – Wrikken Jun 22 '14 at 09:07
  • @Wrikken yes, it does depend on your environment. I'd go with something closer to #2 except that I'd build the document and then feed it to dompdf. Sometimes it's easier to go through the web server because a) dynamic content will be rendered by the server and b) external file references (e.g. images, css) will point where expected. The latter issue is one commonly encountered when people try to use dompdf and a local file or load_html(). – BrianS Jun 23 '14 at 20:33
  • @Wrikken will the 1st method work if my `$file` doesn't end with `html` ?? because I have a similar problem. Browser can open url `http://localhost:1111/report/get/myfile`, but the same url won't work with DOMPDF. It gives file not found – mrid Apr 11 '20 at 13:19