用PHP编写/绘制PDF模板文档 [英] Writing/Drawing over a PDF template document in PHP

查看:190
本文介绍了用PHP编写/绘制PDF模板文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用PHP在现有的pdf文档上书写/覆盖文本.我希望做的是拥有一个可以充当模板的pdf文档,并通过打开模板doc,覆盖相关文本并将结果作为新文档来填补空白.模板文档是单个页面,因此不需要页面合并/操作.

I'd like to be able to write/overlay text over an existing pdf document using PHP. What I am hoping to do is have a pdf document that can act as a template, and fill in the gaps by opening the template doc, overlaying the relevant text, and serving the result as a new document. The template document is a single page so page merging/manipulation is not necessary.

有没有免费的库可以做到这一点?我应该看什么地方?我所做的大多数搜索似乎都是在合并文档/添加页面,而不是在现有页面上覆盖内容.

Are there any free libraries that can do this? Anywhere I should look? Most searches I've done seem to deal with merging documents/adding pages, instead of overlaying content over an existing page.

谢谢.

* 这是我所做的: 1.下载FPDF 2.从

* Here is what I did: 1. Download FPDF 2. Download FPDI + FPDF_TPL from

http://www.setasign.de/products/pdf -php-solutions/fpdi/downloads/

以下是任何未来流浪者的示例代码(改编自www.setasign.de的示例):

Here is some sample code for any future wanderers (adapted from the samples at www.setasign.de):

<?php 
include('fpdf.php'); 
include('fpdi.php'); 

// initiate FPDI 
$pdf =& new FPDI(); 
// add a page 
$pdf->AddPage(); 
// set the sourcefile 
$pdf->setSourceFile('templatedoc.pdf'); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
// use the imported page as the template 
$pdf->useTemplate($tplIdx, 0, 0); 

// now write some text above the imported page 
$pdf->SetFont('Arial'); 
$pdf->SetTextColor(255,0,0); 
$pdf->SetXY(25, 25); 
$pdf->Write(0, "This is just a simple text"); 

$pdf->Output('newpdf.pdf', 'D'); 
?>

推荐答案

看看 FPDI库 FPDF 的附加模板注释.

Have a look at the FPDI Library an add on to FPDF for template annotation.

它还可以附加到另一个 TCPDF 流行的PHP PDF库.在此之后的步骤与常规PDF创建相同.

It can also bolt-on to TCPDF, another popular PHP PDF library. An existing PDF is used as the base of a page, instead of a blank, after that the procedures are the same as regular PDF creation.

这篇关于用PHP编写/绘制PDF模板文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆