0

The short : I am trying to make this work :

$blank_pdf_form = "blankform.pdf";
$cmd = "pdftk $blank_pdf_form fill_form - output -";

$descriptorspec = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w"),
   2 => array("pipe", "w")

);

$process = proc_open($cmd, $descriptorspec, $pipes);

if (is_resource($process)) {

    //row2xfdf is made-up function that turns HTML-form data to XFDF
    fwrite($pipes[0], raw2xfdf($_POST));
    fclose($pipes[0]);

    $pdf_content = stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    $return_value = proc_close($process);

    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="output.pdf"');
    echo $pdf_content;
}

Happily stolen here :How to pass variables as stdin into command line from PHP

My issue

It doesn't work with following message :

Sorry, home directories outside of /home are not currently supported. 
See https://forum.snapcraft.io/t/11209 for details.

My understanding :

I am on ubuntu, pdftk is provided as a snap hence has very restricted access to the filesystem. Running from php (user www-data) restricts this even more.

What I did/try :

First errors were asking for directories to exist /var/www/snap/pdftk/... I created all of them manually granting 777. Nothing changed. I created a tmp folder with 777 in /media and performed snap connect pdftk:removable-media :removable-media. php can access files when they are there. But still the same error with pdftk.

Any idea on how to fix this ?

Where should the pdf be to be usable by pdftk ? I was thinking of using multiple pipes 1 for the pdf and 1 (x)fdf bu can't find whether it can be done or not?

Tuckbros
  • 417
  • 3
  • 13
  • Is there any reason why you must use a snap instead of a normal package? – notautogenerated Mar 21 '20 at 21:26
  • Due to what I saw (and experienced), it is not anymore in the standard package repository of ubuntu (18.04.3 LTS). – Tuckbros Mar 22 '20 at 22:30
  • Right. There is a replacement in newer versions of Ubuntu (18.10 onwards), and if you want to run on a stable version and are not on a hurry you can even wait for 20.04. If that is not an option, maybe https://github.com/mikehaertl/php-pdftk/issues/150 can help. Disclaimer: I am the main author of that replacement. – notautogenerated Mar 23 '20 at 18:02

1 Answers1

0

faced with such problem too.

Resolved it with changing home directory for www-data user to /home/www and now it's working well

cod
  • 390
  • 3
  • 5