【发布时间】:2011-02-20 09:40:33
【问题描述】:
我需要通过 PHP 生成 pdf 格式的引号,并带有从数据库中检索的模板和动态值。
可行吗?
【问题讨论】:
-
请注意:使用 PHP 创建 PDF 非常繁琐。调整尺寸、定位……让自己有时间进行调整;)
我需要通过 PHP 生成 pdf 格式的引号,并带有从数据库中检索的模板和动态值。
可行吗?
【问题讨论】:
更新:我最近看到有人对此表示赞同,并想补充一点,wkhtmltopdf 对于大多数应用程序来说可能是一个更好的选择。
基本上,您首先创建您的 pdf 模板,然后将其加载到新的 FPDI 对象中并使用 FPDF 函数在模板上“绘制” - 很像 Photoshop 图层的工作方式。
$pdf = new FPDI();
$pdf->setSourceFile('template.pdf');
$tpl = $pdf->importPage(1);
$pdf->addPage();
$pdf->useTemplate($tpl); <- template is imported
$pdf->setXY(10, 20);
$pdf->write(100, "Hi there"); <- write or draw something on the template
$pdf->output('newpdf.pdf', 'D'); <- ready, save or output your pdf
【讨论】:
print("this is your product:%s",$name)。在演示中似乎不是这样。
如果您负担得起许可费用,PDFLIB 有一个很好的模板系统,他们称之为“块”。您在 Acrobat 中将块绘制到源模板上,为其指定名称,然后在 PHP 代码中发出“用以下文本/图像/eps 填充此块”很简单。
一旦打开模板/加载字体/等的所有管家代码完成,填空代码归结为:
PDF_fill_textblock($pdf, $pagehandle, $blockname, "Text to insert", 'fitting method arguments');
PDF_fill_imageblock($pdf, $pagehandle, $blockname, $imagehandle, 'fitting method arguments');
PDF_fill_pdfblock($pdf, $pagehandle, $blockname, $pdfhandle, 'arguments here');
【讨论】: