three3
three3

Reputation: 2846

domPDF inline PHP

I am working on creating a PHP script to convert my HTML/CSS/PHP pages into a PDF. I have come across the class domPDF and I have uploaded all files to my server. I am trying to wrap my head around this and I have wrote this sample script to see if I could get it to work. The script is:

ob_start() ;

require_once("dompdf_config.inc.php");

$file= file_get_contents('http://www.yahoo.com');

$dompdf = new DOMPDF();
$dompdf->load_html_file($file);
$dompdf->render();
$dompdf->stream("sample.pdf");

And I am getting this error:

"Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Permission denied on <!DOCTYPE html> <html lang="en-US" class="y-fp-bg y-fp-pg-grad bkt701" style=""> <!-- m2 template --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Yahoo!</title> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <meta name="description" content="Welcome to Yahoo!, the world's most visited home page. Quickly find what you're searching for, get in touch with friends and stay in-the-know with the latest news and information."> <meta name="keywords" content="yahoo, yahoo home page, yahoo homepage, yahoo search, yahoo mail, yahoo messenger, yahoo games, news, finance, sport, entertainment"> <script type="text/javascript"> //Roundtrip rtTop = Number(new Date()); document.documentElement.className += ' jsenabled'; </script> <script type="text/javascript"> (function () { //refresh check var d=document,c=";\ in /home/public_html/Sandbox/include/dompdf.cls.php on line 329"

Upvotes: 1

Views: 6351

Answers (2)

Ben D
Ben D

Reputation: 14479

I think you want to use:

$dompdf->load_html($file);

rather than

$dompdf->load_html_file($file);

Upvotes: 4

JJJ
JJJ

Reputation: 33163

I'm not familiar with domPDF, but judging by the error message and the function's name, I assume load_html_file() expects a filename but you're giving it the contents of a HTML file. Try $dompdf->load_html_file( 'http://www.yahoo.com' ) or find a function that accepts a HTML string as a parameter.

Upvotes: 2

Related Questions