保存并下载 PDF

发布于 2024-12-09 05:51:29 字数 491 浏览 0 评论 0原文

我需要一起做两件事&同时与 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() 单独/单独完成,上面的工作正常,但是当我尝试将它们一起运行时,如图所示上面,它只是崩溃了。

任何帮助/建议将不胜感激。

I need to do 2 things together & at the same time with DOMPDF.

I need to do the following together - is this possible?

//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()); 

The above works fine if $dompdf->stream and $dompdf->output() are done separately/individually , but when I try to run them together as shown above, it just crashes.

Any help/advice would be really appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不吻晚风 2024-12-16 05:51:29

为什么不先将它们交换为文件,然后将创建的文件流回来?

$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);

Why dont you swap them round create the pdf first as a file and then stream the created file back ?

$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);
一杆小烟枪 2024-12-16 05:51:29

回复晚了但可能会对后续有所帮助。

设置附件 true 或 1

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

如果您只是寻找下载,则不需要 file_put_contents()

Answering late but might be will help onward.

on set attachment true or 1

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

No need of file_put_contents() if you are just looking for download

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文