由TCPDF创建的膨胀PDF [英] Bloated PDF created by TCPDF

查看:90
本文介绍了由TCPDF创建的膨胀PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用PHP开发的Web应用程序中,我们使用TCPDF库生成报价和发票(非常简单,只有一页).

In a web app developed in PHP we are generating Quotations and Invoices (which are very simple and of single page) using TCPDF lib.

该库的运行非常好,但它似乎会生成非常大的PDF文件.例如,在我们的案例中,它生成的PDF文件最大为4 MB(+/-几个KB).

The lib is working just great but it seems to generate very large PDF files. For example in our case it is generating PDF files as large as 4 MB (+/- a few KB).

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

How to reduce this bloating of PDF files generated by TCPDF?

这是我正在使用的代码段

Here is code snippet that I am using

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

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

Hope this code fragment will give some idea?

推荐答案

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

Finally I have managed to solve the problem.

问题在于,我错误地在网页中插入了指向电子邮件ID的链接,该链接已呈现为PDF.只需删除此链接,生成的PDF的大小就减少到260 kb!

The problem was that by mistake I had inserted a link to email id in the web page that was getting rendered to PDF. By just removing this link the size of the generated PDF went down to just 260 kb!

感谢所有尝试帮助我解决此问题的人.

Thanks everyone who tried to help me out in solving this problem.

这篇关于由TCPDF创建的膨胀PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆