using PHP to create PDF, without using PHP's FDF functions
Is there any way to create a FDF file within PHP without using the dead FDF functions? I am aware that you can use pdftk
to create a PDF from an existing FDF f开发者_Go百科ile, but I need to create the FDF file first with one field value set.
Or, is there a way to set one field in a PDF using PHP (skipping the FDF file creation) before allowing a user to download it?
For the heck of it, I tried creating an FDF file in PHP using fopen
- did not work. I also know there is a generate_fdf
operation within pdftk
, but this does not allow me to set a specific value, at least not that I can see.
Does anybody know what an answer could be? I am pretty stuck. Unfortunately, I have no control over telling the client to scrap the full PDF (and instead use a webform).
With PDFTK you need two pieces to complete the puzzle. First you need FDF with the data, and secondly an original PDF with appropriately named form fields. PDFTK merges the data into the PDF.
To answer the FDF question first check out this excellent article, http://koivi.com/fill-pdf-form-fields/ that also includes a method to help generate the FDF.
Once you have the FDF with your data you can use PDFTK's fill_form function
You can keep the document editable by using passthru() instead of readfile($temp_file) and outputting to stdout instead of a file name by using the "output - " parameter. Also important is refraining from forcing a document disposition. If you try to force a file download rather than opening it in the browser you'll end up with an uneditable and unsaveable mess.
example:
header("Content-type:application/pdf");
passthru("pdftk ".$original." fill_form ".$fdf." output -");
die();
This will open it in the browser using the Reader plugin. You'll then be able to edit and print the filled form fields, but I still haven't figured out a way to save a copy with the changes. I'm currently chasing Adobe sales for other options.
As noted elsewhere, do not use PDFTK's option "flatten".
The original PDF must not include any passwords.
If I understand you correctly, you just don't want to use the FDF library in particular?
Have you tried TCPDF? See http://www.tcpdf.org/
If you want to use an existing PDF file as a template and only add some values, use the extending FPDI which extends TCPDF: http://www.setasign.de/products/pdf-php-solutions/fpdi/
精彩评论