I have a page in which there is a printable pdf, I want the printed pdf to be saved in a folder in the form of a file Please help me!
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename='', $stream=TRUE, $paper = 'Letter', $orientation = 'portrait')
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper($paper, $orientation);
$dompdf->render();
if ($stream) {
$dompdf->stream($filename.'.pdf', array("Attachment" => 0));
} else {
return $dompdf->output();
}
}
CodePudding user response:
Checking DOMPDF sources we can quickly find, that $dompdf->stream()
does not support file://
protocol and thus can only be used for streaming PDF to browser.
However, $dompdf->output()
will return whole PDF as a string, so all you need is to save a string to file.
file_put_contents('my.pdf', $dompdf->output());
CodePudding user response:
Step1: Use the Dompdf output() to get the PDF content.
Step2: Use PHP file_put_contents() function to insert the content in your PDF file.
$dompdf->render();
$output = $dompdf->output();
$fileName = 'myDocument.pdf';
$path = "pdf_files/".$fileName;
file_put_contents($path, $output);