Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to save DOMPDF generated content to file? [closed]

I am using Dompdf to create PDF file but I don't know why it doesn't save the created PDF to server.

Any ideas?

require_once("./pdf/dompdf_config.inc.php");     $html =       '<html><body>'.       '<p>Put your html here, or generate it with your favourite '.       'templating system.</p>'.       '</body></html>';      $dompdf = new DOMPDF();     $dompdf->load_html($html);     $dompdf->render();     file_put_contents('Brochure.pdf', $dompdf->output()); 
like image 466
TomTom Avatar asked Jan 04 '12 01:01

TomTom


People also ask

How do I save Dompdf generated content?

'<p>Put your html here, or generate it with your favourite '. 'templating system. </p>'. '</body></html>'; $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->render(); $output = $dompdf->output(); file_put_contents('Brochure.

How do I create a PDF using Dompdf?

Basic Usage (Convert HTML to PDF) The following example shows how to use Dompdf to convert HTML and generate PDF with minimal configuration. Specify the HTML content in loadHtml() method of Dompdf class. Render HTML as PDF using render() method. Output the generated PDF to Browser using stream() method.

How do I change the page size of a PDF in Dompdf?

How do I change page size in Dompdf? $dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait'); You can use 'letter', 'legal', 'A4', etc.. With dompdf 0.6 you can also use the CSS @page rule to set your page size/orientation. e.g. @page { size: a4 landscape; } or @page { size: 360pt 360pt; } .


2 Answers

I have just used dompdf and the code was a little different but it worked.

Here it is:

require_once("./pdf/dompdf_config.inc.php"); $files = glob("./pdf/include/*.php"); foreach($files as $file) include_once($file);  $html =       '<html><body>'.       '<p>Put your html here, or generate it with your favourite '.       'templating system.</p>'.       '</body></html>';      $dompdf = new DOMPDF();     $dompdf->load_html($html);     $dompdf->render();     $output = $dompdf->output();     file_put_contents('Brochure.pdf', $output); 

Only difference here is that all of the files in the include directory are included.

Other than that my only suggestion would be to specify a full directory path for writing the file rather than just the filename.

like image 140
startupsmith Avatar answered Sep 18 '22 01:09

startupsmith


I did test your code and the only problem I could see was the lack of permission given to the directory you try to write the file in to.

Give "write" permission to the directory you need to put the file. In your case it is the current directory.

Use "chmod" in linux.

Add "Everyone" with "write" enabled to the security tab of the directory if you are in Windows.

like image 22
Charlie Avatar answered Sep 21 '22 01:09

Charlie