在PHP开发的Web应用程序中,我们使用TCPDF lib生成报价和发票(这些非常简单且只有一个页面)。TCPDF创建的膨胀PDF
该库工作得很好,但它似乎产生非常大的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
希望这个代码片段会给出一些想法的代码片段?
首先我们需要知道,为什么它变得如此臃肿起来。因此,如果您可以给我们一个使用TCPDF的代码示例,这个代码会膨胀,您是否使用了pdf中的图像? – jigfox 2010-06-08 14:06:21
我不知道为什么它臃肿,所以我怎么能说。我花了3天的时间试图找出通货膨胀的原因,但没有取得任何成功。 :( – 2010-06-09 15:02:44
瑜伽,你将需要显示一个PDF示例。PDF包含图像或其他媒体吗? – 2010-06-09 15:15:14