tags:

views:

99

answers:

1

I am trying to Fill in a PDF from PHP script. I am following the article by Sid Steward at the following URL.

I have configured PDFTk package on CentOS linux distribution and I am able to execute the pdftk from the command prompt and it merges the FDF form with the PDF and successfully generates the flattened(Filled) PDF. I am using following command to test the Pdftk using shell.

pdftk /tmp/form.pdf fill_form /tmp/fdfbm0pe7 output /tmp/filledform.pdf flatten

But When try to execute a similar command through PHP, I am getting the error. The passthru command is failing with error code 11. Following is the php code I am using to execute the command:

$command = 'pdftk form.pdf fill_form '. $fdf_fn. ' output - flatten';
passthru($command, $error);

The $fdf_fn above has the FDF file name. The form.pdf is the fill-able pdf form. Both the form.pdf and the PHP script file from which I have given the above lines of code are in the same folder. I have checked that PDFtk is executing correctly through PHP by echoing shell_exec('pdftk') and it was returning the standard help details.

Just to provide more details, the path to pdftk is /usr/bin/ and PHP script and PDF form files are located under /var/www/html/pdfmerge.

Can some one please guide what I am doing wrong that the command execution through PHP is failing with error code 11?

A: 

I had a similar issue to what you were having and it turns out that PHP didn't have access to read the .pdf, .fdf and did not have access to create the flattened .pdf file in the /tmp directory.

to see if that is the issue try doing

chmod 777 /tmp

to see if that fixes the issue. I wouldn't recommend leaving at 777 but maybe moving it back to 700 or so.

jostster