首页 > 解决方案 > 如何从已保存在数据库中的 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;

 ///////////////////////////////////////////////////////////

任何人都有解决方案。

标签: phppdfhtml2pdf

解决方案


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;
        }

这对我有用。


推荐阅读