We help IT Professionals succeed at work.
Get Started

pdftk shell script works fine when run from command line, but not when invoked by PHP

3,639 Views
Last Modified: 2012-05-06

I'm running pdftk, a program that deals with PDFs, on a shared server running Linux. Among its operations, it can rotate a pdf 180 degrees and fill a pdf form with .fdf data.

I've installed pdftk and have been able to run operations from the command line without any problem. I'm merging .fdf ata with a pdf form I've created and outputting to a folder on the server. This works great when run from the command line.

However, when I invoke pdftk through a php file in the browser to merge the .fdf data with the pdf, using the exact same script, the process hangs and eventually produces a 0KB pdf file instead of the ~28KB pdf produced when run from the command line. I let the program run its course and the checked my site's error log. Here is the error this
attempt produced:

[Thu Mar 19 16:42:26 2009] [error] [client 24.61.106.202] sh: line 1:  8951 Killed  /home/sweetbel/bin/pdftk-1.41/pdftk/pdftk recipe_card_01.pdf fill_form test.fdf output /home/sweetbel/public_html/pdf/recipe_test.pdf, referer: http://sweetbellpaper.com/pdf/

Code from my php file, with full and correct paths:
passthru( '/home/sweetbel/bin/pdftk-1.41/pdftk/pdftk recipe_card_01.pdf fill_form test.fdf output /home/sweetbel/public_html/pdf/recipe_test.pdf' );

Here's the funny thing ... my php file invoking pdftk works just fine when I'm using the "rotate pdf 180 degrees" operation (/home/sweetbel/bin/pdftk-1.41/pdftk/pdftk recipe_card_01.pdf cat 1-endS output /home/sweetbel/public_html/pdf/recipe_test.pdf). So it seems the conflict is with the fill_form operation itself.

Does anyone have a clue as to why this is happening?

Thanks,
Jennifer
passthru( '/home/sweetbel/bin/pdftk-1.41/pdftk/pdftk recipe_card_01.pdf fill_form test.fdf output /home/sweetbel/public_html/pdf/recipe_test.pdf' );

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE