【发布时间】: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