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

Pablo Gosse created an issue. See original summary.

Pablo Gosse’s picture

Title: PDFtk Generating PDFs of 0 bytes » FillPDF Generating PDFs of 0 bytes when using local PDFtk
Pablo Gosse’s picture

The 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

Liam Morland’s picture

To 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.

Pablo Gosse’s picture

Thanks 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

Pablo Gosse’s picture

Hi 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:

$method = variable_get('fillpdf_service');
  if (empty($method)) {
    drupal_set_message(t('FillPDF is not configured.'), 'error');
    drupal_goto();
  }

What I find incredibly strange is that when I output $method via watchdog() I get nothing, yet if I use drush I get:

root@pg-lib-wwwd-02 /var/www/html/sites/all/modules/fillpdf (master *=) # drush vget fillpdf_service
fillpdf_service: pdftk

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

Pablo Gosse’s picture

So 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.

gossep@pg-lib-wwwd-02:~$ which pdftk
/usr/bin/pdftk
gossep@pg-lib-wwwd-02:~$ ls -l /usr/bin/pdftk
lrwxrwxrwx 1 root root 15 Feb 28 15:52 /usr/bin/pdftk -> /snap/bin/pdftk
gossep@pg-lib-wwwd-02:~$ ls -l /var/www/html/sites/default/files/fillpdf/nbca_archival_reproduction_agreement_16.pdf
-rw-rw-r-- 1 www-data www-data 616752 Jun  9  2016 /var/www/html/sites/default/files/fillpdf/nbca_archival_reproduction_agreement_16.pdf
gossep@pg-lib-wwwd-02:~$ pdftk /var/www/html/sites/default/files/fillpdf/nbca_archival_reproduction_agreement_16.pdf cat output /home/gossep/test.pdf
Error: Unable to find file.
Error: Failed to open PDF file:
   /var/www/html/sites/default/files/fillpdf/nbca_archival_reproduction_agreement_16.pdf
Errors encountered.  No output created.
Done.  Input errors, so no output created.

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

wizonesolutions’s picture

Try 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.

Pablo Gosse’s picture

Solution 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

Liam Morland’s picture

Status: Active » Fixed

Thanks. I've made a follow-up about improving the error message: #3036845: Improve error message when pdftk fails.

Pablo Gosse’s picture

Thanks 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

Liam Morland’s picture

You 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.