Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We just moved from Scientific Linux to Ubuntu, and as a result have moved from FillPDF Local Server to locally installed PDFtk.
All PDFs that are generated are now 0 bytes. There are no related errors showing up in the Drupal logs, and in fact I see a notice from the FillPDF module that the PDF was created (User generated form "nbca_archival_reproduction_agreement.pdf" for node "NBCA Reproduction Form".).
I'm also not seeing any errors in the server logs either.
Has anyone else encountered this problem? Any advice would be greatly appreciated.
Thanks,
Pablo
Comments
Comment #2
Pablo Gosse CreditAttribution: Pablo Gosse as a volunteer and commentedComment #3
Pablo Gosse CreditAttribution: Pablo Gosse as a volunteer and commentedThe version of pdftk being used is 2.02.
To test that pdftk itself is working, I took the original PDF that is being manipulated and ran the following command from the help page:
pdftk nbca_archival_reproduction_agreement.pdf cat 2-3 output out1.pdf
The resulting out1.pdf was correct, with the first page removed.
Any ideas or thoughts would be greatly appreciated.
Cheers,
Pablo
Comment #4
Liam MorlandTo start debugging, I suggest you edit FillPDF so that it outputs the exact pdftk command that it is using and try running that on the command line.
Comment #5
Pablo Gosse CreditAttribution: Pablo Gosse as a volunteer and commentedThanks Liam. I will definitely give that try.
FYI I've isolated the problem to _fillpdf_build_options_object. It appears that the $data parameter is null, which would explain things.
I'll post back here once I've verified that, and isolated the pdftk command.
Cheers,
Pablo
Comment #6
Pablo Gosse CreditAttribution: Pablo Gosse as a volunteer and commentedHi Liam. Here's the command being executed:
/snap/bin/pdftk '/var/www/html/sites/default/files/fillpdf/nbca_archival_reproduction_agreement_16.pdf' fill_form '/var/www/html/sites/default/files/fillpdf/nbca_archival_reproduction_agreement_16.pdf.xfdf' output - flatten drop_xfa
I also debugged the data being passed to the fillpdf_execute_merge() function.
It looks like the $method, $fields, $fillpdf_info, $flatten, and $image_data are all empty. Now, right before they are used there is an explicit check on $method:
What I find incredibly strange is that when I output $method via watchdog() I get nothing, yet if I use drush I get:
I'm done for the day so will continue investigating this tomorrow. If you're able to provide any further ideas based on the information I've provided I would be very appreciative.
Cheers,
Pablo
Comment #7
Pablo Gosse CreditAttribution: Pablo Gosse as a volunteer and commentedSo it turns out that this is an issue specific to Ubuntu 18.04 and the pdftk library. I'm not sure why, but I think that's definitely the cause.
There was some useful info on this page:
https://wilransz.com/pdftk-on-ubuntu-18-04/
However, the suggested fix there didn't work for me.
As can be seen in the above code, the source file exists, yet pdftk still says it can't find it.
Continuing to look for a solution. If anyone has any ideas feel free to share.
Cheers,
Pablo
Comment #8
wizonesolutionsTry to build pdftk from source instead of using the snap. That might work. If you can run Docker on the server, you could also try FillPDF LocalServer.
Comment #9
Pablo Gosse CreditAttribution: Pablo Gosse as a volunteer and commentedSolution found. It turns out that in Ubuntu 18.10 there was a Java port of pdftk added - pdftk-java.
https://packages.ubuntu.com/disco/pdftk-java
I installed that and it works perfectly.
I'll add a note to the module homepage indicating this for anyone who is using Ubuntu 18.04.
Thanks all for your input on this. Greatly appreciated.
Cheers,
Pablo
Comment #10
Liam MorlandThanks. I've made a follow-up about improving the error message: #3036845: Improve error message when pdftk fails.
Comment #11
Pablo Gosse CreditAttribution: Pablo Gosse as a volunteer and commentedThanks Liam. If it's okay with you I'd like to take on the development of this patch. I've contributed patches to a few projects, and would love the opportunity to contribute here as well.
I assume that we'd be looking to:
- catch any unhandled exceptions from pdftk
- provide a useful error message
Would we also be looking to provide in that error message info about alternative solutions, such as pdftk-java? Or should it be limited to the fact that an error occurred. I can definitely see the advantage to providing info about alternative solutions, but could also see how that info could quickly become dated. So perhaps that additional info should be placed in the documentation, and the error message could refer to the documentation for resolution?
Cheers,
Pablo
Comment #12
Liam MorlandYou are most welcome to do this development. The error should just be about what happened. As it is, it appears to work, except the output file is empty. Instead, the error generated by pdftk should be surfaced to the user. The online documentation is the place for information about alternatives.