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?