php - 如何从已保存在数据库中的 pdf 内容生成 pdf
问题描述
由于我不希望将 pdf 存储在文件夹中,而是 PDF 输出需要存储在 db 中,如下所示。
PDF is created using html2pdf.class.php
/////////////////////////////////////////////////////////////////////
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($pdf_invoice_content, isset($_GET['vuehtml']));
$pdfdata = $html2pdf->Output('document.pdf', 'S');
////////////////////////////////////////////////////////////////////
通过从 db 中获取数据,我想创建 pdf。所以我确实喜欢这个,但 pdf 没有打开。
//////////////////////////////////////////////////////////
$file_size = sizeof($pdfdata); // data fetch from db
$file_name = 'test1.pdf';
header("Content-length: $file_size");
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=$file_name");
echo $pdfdata;
///////////////////////////////////////////////////////////
任何人都有解决方案。
解决方案
I have stored the pdf data in db as blob and show the pdf like below.
$pdfdata = $pdf_invoice_content;
$file_name ='test1.pdf';
if($pdfdata){
header('Content-type: application/pdf;base64');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
echo $pdfdata;
}
这对我有用。
推荐阅读
- google-apps-script - 如何使用 Google Web App 显示自定义网页?
- html - 使用 Xampp 自动生成的 Div
- android - 从 Kotlin (Android) 中的监听器 onSuccess() 返回一个值
- image - 为什么将网站部署到 Vercel 时图像大小不同?
- javascript - Js用相同的按钮翻转/取消翻转
- php - 如何在我的多维关联数组中回显正确的键?
- angular - 如何在 Angular 材料中为 Mat Date Range Picker 设置值
- r - R:无法读取 API 调用 - open.connection 中的错误(con,“rb”)
- delphi - 使用 Helpintfs::IHelpSystem 在 C++Builder 中给出错误“抽象类”
- css - 在 Material UI 中为按钮组件添加边距