Сохраните и загрузите PDF

Мне нужно сделать 2 вещи вместе и одновременно с DOMPDF.

Мне нужно сделать следующее вместе - это возможно?

//print the pdf file to the screen for saving
$dompdf->stream("pdf_filename_".rand(10,1000).".pdf", array("Attachment" => false));
//save the pdf file on the server
file_put_contents('/home/stsnew/public_html/pdf/file.pdf', $dompdf->output()); 

Выше работает нормально, если $dompdf->stream а также $dompdf->output() делается отдельно / индивидуально, но когда я пытаюсь запустить их вместе, как показано выше, он просто падает.

Любая помощь / совет будет очень признателен.

1 ответ

Решение

Почему бы вам не поменять их местами, сначала создайте PDF-файл как файл, а затем верните созданный файл обратно?

$file_to_save = '/home/stsnew/public_html/pdf/file.pdf';
//save the pdf file on the server
file_put_contents($file_to_save, $dompdf->output()); 
//print the pdf file to the screen for saving
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="file.pdf"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file_to_save));
header('Accept-Ranges: bytes');
readfile($file_to_save);

Ответить поздно, но, возможно, поможет в дальнейшем.

по установленному приложению true или 1

$dompdf->stream("pdf_filename_".rand(10,1000).".pdf", array("Attachment" => true));

Нет необходимости в file_put_contents(), если вы просто ищете загрузку

Другие вопросы по тегам