Combine FDF data into a PDF file using PHP

Is it possible to combine FDF data with a PDF file using only PHP? Or is there no way other than using a third-party command line tool for this?

If so, can someone point me towards one?

I currently output the FDF file to a browser, hoping that it redirects the user to a completed PDF file, but for some people this is not the case. The contents of the FDF are displayed, although I use the header ('Content-type: application / vnd.fdf');

+20
php pdf fdf xfdf
07 Sep '09 at 15:50
source share
4 answers

In the future, there seems to be no reliable way to do this without a third-party application. Pdftk ( http://www.accesspdf.com/pdftk/ ) turned out to be my solution.

First I generated the FDF file as before, and then merged it into my PDF file using the following PHP code

header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="Download.pdf"'); passthru("pdftk file.pdf fill_form data.fdf output - "); exit; 

It was a lot easier than I thought. This instantly eliminates the need to crack headers and file extensions to ensure that all browsers handle FDF properly, as it simply forces the browser to download the PDF file.

If you want the output PDF file no longer edited, use

  passthru("pdftk file.pdf fill_form data.fdf output - flatten"); 

Sorry, if this is basic material, I just thought that I would put it all in one place so that people do not experience the headache that I suffered.

NB If your PATH variable is not set, you will need to use the full path to pdftk ie

  passthru("/usr/local/bin/pdftk file.pdf fill_form data.fdf output - flatten"); 
+30
07 Sep '09 at 18:28
source share

There is another way to not use passthru or pdftk, but only a script made in 2004, but still works well: forge_fdf

this will help you create a fdf that you can easily format in your pdf format, which means that you

Save this in a php file, say generatePdf.php

 require_once('forge_fdf.php'); // leave this blank if we're associating the FDF w/ the PDF via URL $pdf_form_url= ""; // default data; these two arrays must ultimately list all of the fields // you desire to alter, even if you just want to set the 'hidden' flag; // // $fdf_data_names= array(); // none of these in this example $fdf_data_strings= array(); // none of these in this example $fdf_data_strings['email']=mb_strtolower($row_delivreur['firstname']).'.'.mb_strtolower($row_delivreur['lastname']).'@gmail.com'; $fields_hidden= array(); $fields_readonly= array(); // set this to retry the previous state $retry_b= false; header( 'content-type: application/vnd.fdf' ); echo forge_fdf( $pdf_form_url, $fdf_data_strings, $fdf_data_names, $fields_hidden, $fields_readonly ); 

Linking to Pathtoyourpdf / nameofpdffile.pdf # FDF = generatePdf.php will open your PDF file in a browser (alternatively, there is a way to save it to disk, I think I remember), and the field email will be filled with data from MYSQL: mb_strtolower($row_delivreur['firstname']).'.'.mb_strtolower($row_delivreur['lastname']).'@gmail.com'

It works with checkboxes, switch, ... It opens well in firefox, it needs to be tested with other browsers.

Learn more about PDF HACKS

+3
Apr 26 2018-11-11T00:
source share

the easiest way I found to install pdftk on centos:

Install rpmforge repo - http://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-5aabf02717d5b6b12d47edbc5811404998926a1b

then

yum install pdftk

and here it is!

+2
Nov 20 '10 at 7:18
source share

http://www.setasign.de/products/pdf-php-solutions/fpdi/demos/concatenate-fake/

This works, class loading is also linked to the website,

It does not require the passthru / exec command and additional extensions.

Edited in order to say that this does not work with newer versions of PDF version 1.5+, which returned to PDFTK, it is unrealistic, but it works with all pdf files using the "exec" command.

+1
Apr 14 '11 at 9:30
source share



All Articles