What is the perfect way to fill acroforms using CLI Linux tool or NodeJS module?

432 views Asked by At

I have a task where I need to fill in PDF Forms. I think they are called Acroforms but I am not sure. It is opposit to XFA Forms (embedded in PDFs), Acroforms are less dynamic, they don't have many features compared to XFA.

I am coding for NodeJS, so I tried its module pdffiller. This library is only a wrapper for so-called pdftk or PDF Toolkit.
It took me almost one day to figure out how to use it on my Ubuntu 18.04 development laptop. I couldn't install it or compile, so I had to download docker image, unpack it and place compiled pdftk in specific system folders to allow pdffiller to work (lib goes here /usr/lib/x86_64-Linux-gnu/libgcj.so.16.0.0, binary goes here /usr/local/bin/pdftk).

Then there go the forms. Those downloaded from official government webpage (these are tax return forms) are XFA forms, these do not work with pdftk - all I get is a request for password which I don't have.

Error: Failed to open PDF file: 
   tax-return-form.pdf
   OWNER PASSWORD REQUIRED, but not given (or incorrect)
Done.  Input errors, so no output created.

We took the other approach, we bought Adobe Acrobat DC to convert flat PDFs to simple Acroforms. Then we tested again what PDF Toolkit can do. Two problems are blockers, and dim pdftk unusable for us:

  1. No output for Polish diactrict signs (ąęćśżźnó)
  2. No ability to check a checkbox

And the tax form has plenty of those checkboxes!

I would like to as what tool should we use? Is there any opensource or free for commercial use that will fill PDF Forms properly?

Edit: I found the way to select checkboxes. After using pdftk dump_data_fields_utf8 method I got a file with a lot of information about fields:

---
FieldType: Button
FieldName: checkbox3
FieldFlags: 0
FieldJustification: Left
FieldStateOption: Off
FieldStateOption: Yes
---

The checkbox above has FieldStateOption: Off or Yes. Just putting Yes in JSON field-value map mad checkboxes selected.

1

There are 1 answers

0
Marecky On BEST ANSWER

It is doable, but:

  1. there is no utf-8 fonts if one uses 'flatten' option
  2. has to use 'need_appearances' which excludes 'flatten'
  3. Ubuntu's PDF Viewer Evince 3.28.4 doesn't know how to display polish fonts
  4. Firefox, Chrome, Adobe Reader 9 for Linux does display UTF fonts properly.
  5. and fanks for the downvote without explanation why, SO sucks as usual.