在一个用 PHP 开发的 web 应用程序中,我们使用 TCPDF 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
希望这个代码片段能给你一些想法?