由TCPDF创建的膨胀PDF

时间:2010-06-08 14:01:38

标签: php pdf tcpdf

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

lib工作得很好但似乎生成了非常大的PDF文件。例如,在我们的例子中,它生成的PDF文件大小为4 MB(+/-几KB)。

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

以下是我正在使用的代码段

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

希望这段代码片段能给出一些想法吗?

3 个答案:

答案 0 :(得分:0)

您需要查看它在PDF中的含义。它嵌入了大量的图像或字体吗?

您可以使用大量PDF工具检查内容。如果您有Acrobat 9.0,则有一篇博文文章介绍了如何在http://pdf.jpedal.org/java-pdf-blog/bid/10479/Viewing-PDF-objects

执行此操作

答案 1 :(得分:0)

最后我设法解决了这个问题。

问题在于我错误地在网页中插入了一个链接到电子邮件ID,该链接已呈现为PDF。通过删除此链接,生成的PDF的大小降至仅260 kb!

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

答案 2 :(得分:0)

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

相关问题