开发者

Populating PDF form fields with PHP

开发者 https://www.devze.com 2023-03-21 03:16 出处:网络
I am converting a classic ASP application to PHP. In the Classic ASP app, we are programatically populating fields that have been created in PDF documents using a component called ASPpdf.

I am converting a classic ASP application to PHP.

In the Classic ASP app, we are programatically populating fields that have been created in PDF documents using a component called ASPpdf.

I 开发者_高级运维need to reproduce this behavior in PHP, but need to know if PHP can populate PDF fields on its own or if any third party plug in is needed.

Is this functionlity posible in PHP with or without a plug in?

Thanks.

Note: I already have the PDFs created, I do not need to create the actual PDF. I need to grab a preexisting PDF with form fields, populate those form fields and then save that custom PDF.


This is the first google search result I got, is there a reason this doesn't work for you?

http://koivi.com/fill-pdf-form-fields/tutorial.php

UPDATE

After reading a little further, this generates an FDF (which Acrobat can read). To generate an actual PDF you'll need to use this: http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/


The resolution to my problem was to use the same COM component I used in Classic ASP in my new PHP apps. The COM object give me tremendous control over PDF documents.

The component I use is AspPdf

<?php

$pdf = new COM("Persits.Pdf") or die("Unable to instantiate Word");


$pdfdoc = $pdf->OpenDocument( "pdf.pdf" );
$pdffont = $pdfdoc->Fonts("Helvetica-Bold");
$pdfdoc->Form->RemoveXFA();

$pdffield = $pdfdoc->Form->FindField("FirstName");
$pdffield->SetFieldValue("PHP Text", $pdffont);

$pdffile = $pdfdoc->save( "php.pdf" , false);

echo $pdf->version;
$pdf = null;

?>


It looks as though the pdftk PDF toolkit may be able to do this. Reading the manual:

fill_form < FDF data filename | XFDF data filename | - | PROMPT >

Fills the single input PDF’s form fields with the data from an FDF file, XFDF file or stdin. Enter the data filename after fill_form, or use - to pass the data via stdin, like so:

pdftk form.pdf fill_form data.fdf output form.filled.pdf

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号