php-pdftk: Can not write to temp directory
Whenever I try to fill in a form using fillForm I get an error message stating
Error: Failed to open form data file: \n /tmp/php_pdftk_xfdf_uL6Hf2.xfdf\n No output created.
code:
$tempPdf = new \mikehaertl\pdftk\Pdf(__DIR__ . '/Mededelingsformulier_scheiding_2019_2.pdf'); $tempPdf->fillForm($arr = [ 'test' => 'test', ]); $tempPdf->saveAs(__DIR__ . '/tempfile.pdf'); $error = $tempPdf->getError(); $this->assertEquals('', $error);
All files are accessible, other functions work perfectly (getDataFileds, GenerateFdf)
I’m working with Laravel running on an updated Homestead vagrant instance using pdftk from a snap install.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 27 (9 by maintainers)
Commits related to this issue
- Issue #150 Add note about Ubuntu ppa — committed to mikehaertl/php-pdftk by mikehaertl 5 years ago
- Issue #150 Add tempDir option — committed to mikehaertl/php-pdftk by mikehaertl 4 years ago
- Issue #150 Use tempDir for Fdf, Xfdf and Info files — committed to mikehaertl/php-pdftk by mikehaertl 4 years ago
- Merge pull request #177 from mikehaertl/150-tmp-directory-option Issue #150 Add tempDir option — committed to mikehaertl/php-pdftk by mikehaertl 4 years ago
sudo ln -s /snap/pdftk/current/usr/bin/pdftk /usr/bin/pdftkworked for me too…
Okay, I now know what the error is. pdftk is a bit outdated. I believe a version 3.0 is in the works using the open version of Java
However to install pdftk on a recent version of ubuntu is using snap. this will install it in a secure way so that it doesn’t have access to the /tmp folder. That’s why it’s failing out of the box
This works. Maybe to put in your readme ? to avoid using the snaps (or you should rewrite parts of your code to generate fdf files outside of the /tmp folder
Here’s an update:
ppa:malteworld/ppais no longer available.pdftk-javapackage withapttempDir.I’ve copied a part of my after.sh script of my homestead installation. might provide you with a start to a solution…
I found the solution. I was wrong to give permission to the tmp folder 😉
okey i solved the issue, the php can not run pdftk command because the www-data has no permission to run script
Following the suggestions above, manually setting the tempDir resolved the error. For those using Laravel Forge, this would look something like:
On the server:
and then in the code:
Although now there is unrelated issue I’m currently wrestling with:
But I think that may because pdftk was installed using snap. This will require further debugging.