使用PHP填写PDF [英] using PHP to fill in a PDF
问题描述
我需要使用PHP即时填写PDF-不知道从哪里开始.
I need to fill in a PDF, in the fly, using PHP - have no idea where to start.
我目前正在使用PHP在线进行测验-一旦通过了一系列测验,客户端希望让用户下载结业证书"
I'm currently doing quizzes on line using PHP - once a series of quizzes are passed the client wants to let the user download a 'certificate of completion'
证书的PDF在用户名和研究领域上有空白行.
The PDF of the certificate has blank lines for the users name and the area of study.
我的想法是-在PDF中添加2个表单元素,并在我提取证书时让PHP将其填充.
My thought is - add 2 form elements to the PDF, and have PHP pill them in when I pull of the certificate.
但是如何?
还有其他更好的方法吗?
Is there a different, better way?
我需要谨慎"的事情-安装第三方的东西是不可靠的,除非我可以在站点根目录中放置一个lib.我不能保证托管服务提供商会允许我更改PHP配置.
Things I need to be 'cautious' of - installing third party stuff is not reliable, UNLESS I can just drop a lib in the the site root. I can't guarantee the hosting provider will let me change a PHP config.
任何帮助都将受到赞赏-越具体越好.
Any help is appreciated - the more specific, the better.
对不起,目前我没有代码-除了我当前显示PDF的方式-
Sorry I have no code at the moment - other than how I'm currently displaying the PDF -
// show cert
echo '<iframe src="1_cert.pdf" width="1000" height="700">';
谢谢.
好-按照建议使用TCPDF-我已经安装好了,示例页面可以正常工作... 我已经在示例文件夹中放置了一个文件....我已经包含了一个导入调用...
OK - using TCPDF - as suggested - I've installed, and example pages work... I've placed a file in the example folder.... I've included a call to import...
require_once('../tcpdf_import.php');
// create new PDF document
$pdf = new TCPDF_IMPORT('1_cert.pdf');
...other boiler plate copied form other examples...
$pdf->SetDisplayMode('fullpage', 'SinglePage', 'UseNone');
// set font
$pdf->SetFont('times', 'B', 20);
$pdf->setPage(1, true);
$pdf->SetY(50);
$pdf->Cell(0, 0, 'test text', 1, 1, 'C');
$pdf->lastPage();
我得到的错误是"TCPDF错误:setPage()函数上的页码错误:1"
The error I'm getting "TCPDF ERROR: Wrong page number on setPage() function: 1"
推荐答案
好吧,如果您不显示代码,那么我也不会.;)
Ok, if you're not showing code, then neither will I. ;)
我建议使用 TCPDF .
- 使用TCPDF_Import导入PDF
- 在PDF文档中,您可以导航到任何x/y位置(注意:0/0位于左下角).因此,只需将光标"设置到每个字段的位置,然后使用
Cell
或writeHTMLCell
方法插入文本. - 保存PDF文档.
- 将其显示给用户.
- Import the PDF with TCPDF_Import
- In a PDF document, you can navigate to any x/y position, (NB: 0/0 is bottom left). Therefore, simply set your "cursor" to the position to each field, and insert a text with either the
Cell
or thewriteHTMLCell
method. - Save the PDF document.
- Display it to the user.
Voilà.
顺便说一下,FPDI和TCPDF都是常见的PHP库,因此您可以将它们放在基本文件夹中的某个位置,而在公共Web服务器上则不需要其他工具.
By the way, both FPDI and TCPDF are common PHP libraries, so you can just put them somewhere in your base folder, no additional tools should be required on a common web server.
这篇关于使用PHP填写PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!