【问题标题】:Bloated PDF created by TCPDF由 TCPDF 创建的臃肿 PDF
【发布时间】:2011-03-01 04:34:35
【问题描述】:

在一个用 PHP 开发的网络应用程序中,我们使用 TCPDF 库生成报价和发票(非常简单且单页)。

该库运行良好,但它似乎生成了非常大的 PDF 文件。例如,在我们的例子中,它生成的 PDF 文件大至 4 MB(+/- 几 KB)。

如何减少由 TCPDF 生成的 PDF 文件的膨胀?

这是我正在使用的代码 sn-p

ob_start();
                include('quote_view_bag_pdf.php'); //This file is valid HTML file with PHP code to insert data from DB
                $quote = ob_get_contents();  //Capture the content of 'quote_view_bag_pdf.php' file and store in variable

                ob_end_clean();

                //Code to generate PDF file for this Quote
                //This line is to fix a few errors in tcpdf
                $k_path_url='';


                require_once('tcpdf/config/lang/eng.php');
                require_once('tcpdf/tcpdf.php');

                // create new PDF document
                $pdf = new TCPDF();

                // remove default header/footer
                $pdf->setPrintHeader(false);
                $pdf->setPrintFooter(false); 

                // add a page
                $pdf->AddPage();

                // print html formated text
                $pdf->writeHtml($quote, true, 0, true, 0); //Insert Variables contents here.

                //Build Out File Name
                $pdf_out_file = "pdf/Quote_".$_POST['quote_id']."_.pdf";

                //Close and output PDF document
                $pdf->Output($pdf_out_file, 'F');
                $pdf->Output($pdf_out_file, 'I');
                ///////////////
enter code here

希望这个代码片段能给你一些想法?

【问题讨论】:

  • 首先我们需要知道,为什么它会变得如此臃肿。因此,如果您能给我们一个使用 TCPDF 的代码示例,那将会很有帮助,您是否在 pdf 中使用图像?
  • 我不知道它为什么会臃肿,所以我怎么知道。我花了 3 天时间试图找出这种通货膨胀的原因,但没有任何成功。 :(
  • Yogi,您需要展示一个 PDF 示例。 PDF 是否包含图像或其他媒体?
  • 如果你想简单快速地使用 tfpdf

标签: php pdf tcpdf


【解决方案1】:

您需要查看它在 PDF 中的内容。是否嵌入了很多图像或字体?

您可以使用许多 PDFtools 检查内容。如果你有 Acrobat 9.0,有一篇博客文章展示了如何做到这一点http://pdf.jpedal.org/java-pdf-blog/bid/10479/Viewing-PDF-objects

【讨论】:

    【解决方案2】:

    我终于设法解决了这个问题。

    问题是我错误地在要呈现为 PDF 的网页中插入了指向电子邮件 ID 的链接。只需删除此链接,生成的 PDF 的大小就降至 260 kb!

    感谢所有试图帮助我解决这个问题的人。

    【讨论】:

      【解决方案3】:

      当前的 TCPDF 版本现在默认包含字体子集,以显着减小 PDF 大小。 查看 TCPDF 网站http://www.tcpdf.org 并咨询官方论坛以获取更多信息。

      【讨论】:

        猜你喜欢
        • 2014-12-30
        • 2017-05-21
        • 2015-03-17
        • 2011-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多