0

I successfully installed pdftk on a VPS. It works fine when I run the commands in command line, but when I run the script on php it does not generate the pdf file. No errors anything. Has anyone had this same issue? When the script is run on php the fdf file is generated but not the pdf.

Here is the code sample i am using.

$fName = 'Ryan';
$lName = 'Kempt';
$dateNow = date('F jS, Y');

$fdf = '%FDF-1.2
1 0 obj<</FDF<< /Fields[
<</T(first_name)/V('.$fName.')>>
<</T(last_name)/V('.$lName.')>>
<</T(date)/V('.$dateNow.')>>
] >> >>
endobj
trailer
<</Root 1 0 R>>
%%EOF';

file_put_contents('test.fdf', $fdf);

$out = '';

exec("pdftk test.pdf fill_form test.fdf output filled.pdf flatten", "2>&1", $out);

when I run pdftk test.pdf fill_form test.fdf output filled.pdf flatten on the terminal the pdf file was generated.

after adding 2>&1 I get error Fatal error: Only variables can be passed by reference

joanb
  • 169
  • 1
  • 1
  • 17
  • try to get message of result: execute command `exec("pdftk test.pdf fill_form test.fdf output filled.pdf flatten 2>&1", $out)`, so you can get console output: `var_dump($out)`. It may contain message about problem. – Taron Saribekyan Mar 11 '17 at 19:01
  • Thank you I just did that and the error is Fatal error: Only variables can be passed by reference – joanb Mar 11 '17 at 19:10
  • Also may be you need to enable SELinux memory excess to allow httpd process use system memory – Taron Saribekyan Mar 11 '17 at 19:14
  • You must declare `$out` before using, e.g. `$out = '';` and after that call `exec` – Taron Saribekyan Mar 11 '17 at 19:15
  • OK I just created a new pdf form to test with only 1 field and I am getting error array(1) { [0]=> string(42) "Done. Input errors, so no output created." } – joanb Mar 11 '17 at 19:33

1 Answers1

0

Check whether you are adding any value with a '/', just remove or replace. I had the same issues and now it is working back!

Sanjoy
  • 51
  • 6