Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Populate PDF's checkbox

I had this question after viewing PDFTK - filling this PDF but got an error.

After talking with the others on this project, we decided it's ok to have the final PDF as read-only and it doesn't need to be editable.

I ran the commands below I can populate the PDF but not the checkbox. Joe (if you're reading this)....is this because of the LiveCycle issue that the checkboxes don't get checked?  If it is, I got approval to buy LiveCycle. I'll get it and see what's going on.

I tried "No" for value, "On", "1" but I don't see the checkbox checked.

1. i-765 is the orig file

2. notsigned.pdf is the file I QPDF-ed to get rid of the password error message

3. Ran this pdftk.exe notsigned.pdf fill_form i-765.txt output OutputFilled.pdf

4. outputfilled.pdf is the populated PDF.
i-765.pdf
notsigned.pdf
OutputFilled.pdf
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Hi Camilla,
Would be helpful if you attach i-765.txt. Thanks, Joe
Avatar of Camillia

ASKER

Yes, I forgot. It's attached.
i-765.txt
Camilla,
I ran this with the two files you posted:

pdftk.exe notsigned.pdf fill_form i-765.txt output OutputFilledJW.pdf

The file that it created is attached. It has nothing filled in. I'll continue to experiment. Regards, Joe
OutputFilledJW.pdf
The file you attached has the name populated so that's working. I wonder why the checkbox doesn't get populated.
> The file you attached has the name populated so that's working.

Well, this is very interesting. When I open the file in Adobe Acrobat XI Pro and Nuance Power PDF Advanced, the Family Name field is not populated. When I open it in Adobe Reader DC, Google Chrome, Nitro Reader, and PDF-XChange Editor, the Family Name field is populated. I cannot explain that.
Odd but how about the checkboxes...why can't they be populated? I'll get LiveCyle if I have to.
Probably because it's an XFA form. Try putting this as the last parameter on your PDFtk generate_fdf and fill_form commands:

drop_xfa

Of course, then all the check-boxes will be clickable (and #15 won't work) in the generated PDF, but it should show the populated check-boxes in the generated PDF. Btw, the Wikipedia article on XFA is worth a read:
https://en.wikipedia.org/wiki/XFA
It helps to explain the viewing variances in PDF products that I mentioned earlier. Regards, Joe
let me see. I'll post back. I read about XFA the other day.
This turned out more difficult than I expected!
> This turned out more difficult than I expected!

Yes, LiveCycle/XFA makes it more difficult than a plain, ol' PDF form.
Going to try this now. Will post back
I've attached the FDF I created with drop_xfa.

How do , for example, set Gender? It looks like this
<<
/V /
/T (Gender[1])
>>

Open in new window


I think I need to put "On" or "Off"

For this field, I did it like this and it worked

<<
/V (Smith)
/T (Line1_FamilyName[0])
>>

Open in new window


I've attached the files.

1. i765.pdf is the orig file

2. dec765.pdf is the decrypted file  using this qpdf --decrypt i-765.pdf dec765.pdf

3. i765.txt is the FDF using this  pdftk.exe i-765.pdf generate_fdf output i-765.txt drop_xfa

4. i-765populated.pdf is the filled form using this pdftk.exe dec765.pdf fill_form i-765.txt output i-765Populated.pdf drop_xfa
i-765.pdf
dec765.pdf
i-765.txt
i-765Populated.pdf
OK, but please understand that this is what happens with the drop_xfa parameter:

(1) The form will be filled.

(2) You will see the checkboxes with an X, such as #7 (Gender) and #8 (Marital Status).

(3) You will see text fields, such as #1 (Family Name, First Name, Middle Name).

(4) You will see the expanded fields, such as #15 (the Yes checkbox, the text in USCIS Office, the Dates, and the Results).

BUT...here's the caveat...it is not really a working form. You'll be able to tick both Genders, all Marital Status choices, etc. Dropping the XFA means that it isn't going to perform as a form the way LiveCycle intended.

If you simply need to display/print/view the form after being filled in via PDFtk fill_form, this method should work for you; but if you need it to be a working form after being filled in via PDFtk fill_form, this method will not work for you.

Regards, Joe
Our messages just crossed. I haven't read your whole post yet, but here's what the Gender lines look like in my FDF:

/V /F
/T (Gender[1])

That fills in fine.

Heading for dinner now. Will check back in here in about an hour or two. Regards, Joe
Let me try.

but if you need it to be a working form after being filled in via PDFtk fill_form, this method will not work for you.

It's ok if the final form is read-only and not editable. I asked the team.

Enjoy dinner :) let me try and I'll post back.
I get this error

<<
/V /
F/T (Gender[1])
>>

Open in new window


Unhandled Java Exception in create_output():
java.lang.ClassCastException: pdftk.com.lowagie.text.pdf.PdfNull cannot be cast to pdftk.com.lowagie.text.pdf.PdfDictionary
   at 0x0059a84e (Unknown Source)
   at 0x0059ad42 (Unknown Source)
   at 0x005e9bd4 (Unknown Source)
   at 0x005ba4a4 (Unknown Source)
   at 0x005b2044 (Unknown Source)
   at 0x0059231e (Unknown Source)
   at 0x004723f1 (Unknown Source)
   at 0x00472045 (Unknown Source)
   at 0x004df3e2 (Unknown Source)
   at 0x004df38a (Unknown Source)
   at 0x00471e74 (Unknown Source)



I've attached the FDF file
i-765.txt
ASKER CERTIFIED SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How do you add it. I open the text file in notepad and then add the "F". Looks like this.

User generated image
Your FDF works. Yours looks like this. What do you open it with ? I open mine with notepad.

User generated image
I can open it with Visual Studio and keeps its format (looks like your FDF). I'll play around with it some more.
I never use Notepad. I use a text editor called KEDIT...been using it for 20+ years...it's a PC look-alike of IBM's VM/CMS editor called XEDIT, which I used in my mainframe days. But I don't recommend KEDIT at this time to others...note this comment at their website (copied here under "Fair Use"):
Mansfield Software Group is no longer actively working on major upgrades of KEDIT. We are in the process of gradually winding the company down, and have limited support resources. For these reasons, we generally do not recommend KEDIT to new users or organizations not already familiar with the program.
Anyway, I know very little about Notepad. You may want to try Notepad++, which is free and generally gets rave reviews:
https://notepad-plus-plus.org/
Visual Studio worked. Thank you so much for all your help.

I have it to the point that I can generate the PDF in a read only format, populated but I get that popup "document enabled extended features". It's not a showstopper for now.
> Visual Studio worked.

Glad to hear it.

> Thank you so much for all your help.

You're very welcome.

> I have it to the point that I can generate the PDF in a read only format, populated

Great news!

> but I get that popup "document enabled extended features". It's not a showstopper for now.

That's a shame, but good to know that it's not a showstopper.

Regards, Joe
thanks :)
> but I get that popup "document enabled extended features". It's not a showstopper for now.

That's a shame, but good to know that it's not a showstopper.

I got rid of the popup. I used that "cat out" command of PDFtk. But this makes the PDF editable with the messed up checkboxes. I run the PDF thru iTextsharp and set the fields to readonly. It worked!
> I used that "cat out" command of PDFtk.
> I run the PDF thru iTextsharp and set the fields to readonly. It worked!

Very nice! Thanks for letting me know — clever trick!