【问题标题】:when using existing template in fpdf/fpdfi displays only the size of the file在 fpdf/fpdfi 中使用现有模板时,仅显示文件的大小
【发布时间】:2015-10-02 06:59:30
【问题描述】:

如何在 fpdf 中使用现有模板。我已经使用过 fpdi 并且可以生成 pdf,但问题是,它没有使用源文件。它只显示文件的大小和我添加的附加文本。这是我尝试过的代码:

public function template_trial(){

$this->load->library('fpdf'); 
$this->load->library('fpdi'); 

$pdf = new FPDI();
// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile("test.pdf");
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm
$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);
// now write some text above the imported page
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'This is just a simple text');
$pdf->Output('tes.pdf','D');
}

pdf 中的示例文本:

此 PDF 的文件大小仅为 12 KB。 这只是一个简单的文本

【问题讨论】:

  • 你能把这个问题隔离到例如一个zip包,所以我们可以重现这个?您使用的是什么版本的 FPDF 和 FPDI?
  • @Setasign,我使用的是 fpdi 1.5.4 和 fpdf 1.7
  • @Setasign,我实际上是在使用这些库 FPDF 和 FPDI 的 codeigniter。
  • @Setasign,在检查了整个事情后,我发现我设置了一个无效的文件路径。给您带来的不便,我深表歉意,谢谢。
  • 所以我对版本问题的猜测是正确的?

标签: php codeigniter pdf fpdf


【解决方案1】:
$mpdf = new mPDF('c','A4','','',11,10,20,10,10,10);
$mpdf->SetImportUse();
$mpdf->SetDocTemplate('layout_bb.compressed.pdf',true); // Add Template
$mpdf->AddPage();

$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'utf-8';
$mpdf->WriteHTML($html); // Put my content on page
$mpdf->Output();

【讨论】:

    猜你喜欢
    • 2020-12-04
    • 1970-01-01
    • 2017-12-08
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 2011-06-03
    相关资源
    最近更新 更多