duangang79177 2010-06-08 14:01
浏览 26
已采纳

由TCPDF创建的膨胀PDF

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

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).

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?

  • 写回答

3条回答 默认 最新

  • dongzhi7763 2010-06-10 11:58
    关注

    Finally I have managed to solve the problem.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题