-1

I have a PHP file Executing a shell command for a tool called PDFTK.

The command works fine when I run it directly from the command line but through the PHP script it self, it does not and doesn't throw an error.

The command i am running is:

$WshShell = new COM("WScript.Shell");
$WshShell->Exec("pdftk Template.pdf fill_form 1406822788.fdf output test2.pdf");

This takes the .fdf data and puts it into the template pdf and then creates the outout of test2.pdf.

Again, works fine when ran directly through the command line.

Any ideas on what I can try to get this to run?

SBB
  • 8,560
  • 30
  • 108
  • 223

3 Answers3

0

Check the return of the method Exec, or try:

exec("pdftk Template.pdf fill_form 1406822788.fdf output test2.pdf");
Marchah
  • 160
  • 14
  • how can I see what exec is returning ? – SBB Jul 31 '14 at 16:58
  • With your existing code: var_dump($WshShell->Exec("pdftk Template.pdf fill_form 1406822788.fdf output test2.pdf")); – Marchah Jul 31 '14 at 17:00
  • the output when running in command line creates the PDF that is desired. When I run it from php, no error and no pdf – SBB Jul 31 '14 at 17:01
  • `object(variant)#2 (0) { } ` – SBB Jul 31 '14 at 17:01
  • but you should simply try: var_dump(exec("pdftk Template.pdf fill_form 1406822788.fdf output test2.pdf")); – Marchah Jul 31 '14 at 17:02
  • `Warning: exec(): Unable to fork [C:\PDFtk\bin\pdftk.exe Template.pdf fill_form 1406822788.fdf output test2.pdf 2>&1] in C:\inetpub\wwwroot\test\testSubmit.php on line 39 NULL ` – SBB Jul 31 '14 at 17:06
0

This may be because your webserver process user does not have privileges to do so. or

Add 2>&1 to the end of your command to redirect errors from stderr to stdout.

See here for further clarification

Community
  • 1
  • 1
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26
-1

It could be many things, but first thing to do is specify the full path to pdftk binary. Chances are, the PHP environment (e.g. apache, nginx, etc) does not have the same PATH variables as your user account.

Andrew
  • 906
  • 7
  • 9