PDFTK not executing from Wordpress Plugin

276 Views Asked by At

I am creating a Wordpress plugin that utilizes PDFTK. I followed the documentation for php-pdftk and my PHP looks like this:

$pdf = new Pdf('/pdf-templates/testpdf.pdf', ['command' => 'C:\Program Files (x86)\PDFtk\bin\pdftk.exe',
            'useExec' => true]);
            $pdf->fillForm($data)
            ->flatten()
            ->saveAs('/generated-pdfs/' . $filename);

I installed php-pdftk using composer and the commands follow through fine. I installed pdftk using sudo apt-get install pdftk and it runs correctly in my Ubuntu terminal. I am developing on a local version of Wordpress hosted in a Docker container with a WSL2 backend.

I have tried installing pdftk locally to my windows machine and passing the path directly as well as using the Ubuntu installation, but neither command passes and both fail. I used the methods from this question to check whether the command was executing and it isn't, which leaves me to believe that my path is the issue, but even passing the absolute path through did not help. I believe it may be something to do with using Docker. This needs to be usable on a live server as well, so I want to avoid using the local windows install but I needed to test if that would work either. I am totally stumped, and any help would be greatly appreciated

I should also mention that even after installing the local version of pdftk, Powershell, CMD and Git Bash did not register it as a command, but I assumed that since I was passing the hard path to the application it didnt matter if my windows PATH was wrong

0

There are 0 best solutions below