Populating PDF Forms

If you're in an industry where standardized forms are the norm, then the holy grail is automatically pushing data from your database into the required PDF. Yes, it's true, we still live in a world where forms consume most of the process. And this probably won't change too much over the years.

If you've ever dreamed of taking those field values and shoving them right into the required form then the included technique file and videos in this mini series will provide you with everything you need.

Not only has the work been done but there's a ton to learn from this wonderfully crafted FileMaker solution. The file is ready-to-go, the solution is based on freely available technology and the videos are worth the price of admission.

Don't miss this series of videos if you have any desire to merge data from FileMaker into preexisting PDF forms!

AttachmentSize
Populating_PDF_Forms.zip8.4 MB

Comments

Excellent work, but I am at lost when it comes to 2 issues :

1) how do you find out what the actual field names are, on a form that you have not created, otherwise how do you use your technique to populate a form like : http://www.dmv.ca.gov/forms/reg/reg195.pdf

2) Can you add the form like the above to your Tech file ?
do you have to recreate all the fields, since it is unrelated to what you have in your tech file ?

I hope this makes sense . Thank you

Xoomaster

@xoomaster

1) I can extract the fields names, including the accepted values used in checkboxes, radio buttons, etc. Then I could automatically create the key-value pairs to save you some time. You would only have to supply the values. A couple of issues when doing this:
* I couldn't differentiate between main and related keys, so I would just create main key-value pairs (your form doesn't have any related data)
* You might not populate all of the fields--you might just populate the text fields in Sections A and G, and after printing the form, the rest of it can be filled out by hand. So you could have a number of keys with no values, which should be OK

2) Yes, you can add the form to the technique file. In terms of integrating this technique file into your own solutions, you don't need the patient-related tables.

These are really good questions. I think I'll make a few changes to the technique file to address your questions. For #2 It will probably be better if I split the technique file into two files, one containing the patient-related data, and one containing the PDF-related data. I'll just need a little bit of time to do this, and I'll probably do a follow-up video that highlights the changes.

Keep the feedback coming!

Sean

Hi Sean,

My main confusion is about access to a preexisting PDF file/Form like I mentioned above.
You mentioned that

"1) I can extract the fields names, including the accepted values used in checkboxes, radio buttons, etc. Then I could automatically create the key-value pairs to save you some time. You would only have to supply the values."

How can you extract fields names and their accepted values on a form, without having Acrobat Professional ?
In your example you manually create these fields on the PDF file usingAcrobat Professional. So is it correct to assume that I would also need Acrobat Professional to do the same with the Form I mentioned above ?

Also the form I mentioned above, is "Locked" so even if I had Acrobat Professional, I don't think I can accurately find data related to the field's names ?

I don't know much about Acrobat, so I apologize for the above questions if they appear redundant.

I think your technique could have a huge impact on the way I do my forms at my work.

Thank you again.

Xoomaster

@xoomaster

I would attempt to extract the field names using the same iText library that I use in the technique file. I wouldn't use Acrobat Professional. Since your DMV form is locked, I may not be able to extract the field names, but I'll try.

Sean

@xoomaster

Hey, I managed to figure out how to extract field names from locked forms. I needed to include two additional Java libraries, both free. I used your DMV form as a test, and here's a screenshot:
http://www.grantwoodtechnology.com/test/populating_pdf_forms_field_info_20080427.jpg

I could use your help with something. Should I automatically create a main key-value pair record for each field found? Maybe you don't want to populate every field, like some of the checkboxes. You would have to delete the unused key-value pairs, or you could just leave them, although that would add clutter.

Sean

This is awesome . I am very much interested in how you extracted the Filed names ?
To answer your question, Yes, it is much easier to delete what is not needed than to create. You could leave a dummy calculation in the field like "" if needed.

Here is a challenge :

Ideally, you want your users to just pick a PDF file and then automatically give them the "Name of the fields" in that PDF. At that time, they will have the option of creating their own calculations and key-value pairs and submitting only what they are interested in filling.

I appreciate your effort. Please let me know how to extract the field names though.

Xoomaster

@xoomaster

I used the iText library to extract the field names, although it couldn't extract field names from your form because it was secured, so I needed help in the form of two other libraries. Sometime soon I'll post the updated technique file so that everyone can inspect the script that extracts the field names (it's not a long script).

"Ideally, you want your users to just pick a PDF file and then automatically give them the "Name of the fields" in that PDF. At that time, they will have the option of creating their own calculations and key-value pairs and submitting only what they are interested in filling."

Well, this technique is really only meant for developers. I personally wouldn't want users trying to create calculations. That seems like a problem waiting to happen.

Sean

@xoomaster

While I can extract the field names from your DMV form, I'm having difficulty populating the form. According to the security settings, the filling of PDF form fields is allowed, so you would think that the fields could be filled programatically as well. Will have to research some more.

Sean

Let me know how it goes. I had tried creating forms and doing Javascript for calculations within PDF forms, but PDFs are generally not easy to work with. One of the major problems include data import and export from and to PDFs.

Please remember the above form is just an example, so don't worry too much if it doesn't work out.
I do like to learn about the above process though.

Does this solution require a particular version of FileMaker Pro? If so, what are the requirements?

What a buzz!
Near the end of last video came a suggestion of getting data off the PDF forms across into filemaker. Is this still a project?
--
Would be really big for emailed applications, registrations ... lots.

Ross

@rscholes

Maybe in a few months. Do you personally need the ability to extract data from PDF forms?

Sean

I am trying to edit the form fields after the script is run and it does not work.

It seems that the form fields that are filled out are not editable and that the form fields that are NOT filled out are gone from the form.

Is that possible?

The workflow that I am setting up requires that users have the ability to edit the form fields.

Please advise. Thanks.

@TonyWhite

Would it be possible to email me a sample PDF? If so, then please send it to chartpacs@gmail.com.

I just sent a before and after PDF by email with the subject line "Editing form fields after the script is run does not work..."

Thanks.

In the technique file, if you click on the Scripts toolbar icon, you'll see the following line:

stamper.setFormFlattening(true);

You can either comment out this line, or set it to false.

Hi

I have set up the solution on both mac & pc with stamper.setFormFlattening(false);

It appears that the process messes with the Extend Features that enable acrobat reader to edit and save the pdf. If I use a pdf form that doesn't have extended features enabled, populate the form from FM and then open in acrobat pro and enable the extended features everything is great.

I was hoping to populate a pdf that already had the extended features enabled. Anyone else experienced this?

If there was an extract data from pdf I would be really interested.

Yes please I am interested in sucking in values from populated pdf forms.....
I currently use the XML return from forms with a transformation xslt to pull into the database, BUT you get multiple emails with the same named file attachment, so you have to save over original, and have no audit process. You can always re-output the XML with a flag for successful import added but it would be nice to do this in Acrobat as reading xml as text can be hard work visually....

Am also interested where to find the bits I need to NOT make the resulting PDF flat, so it can remain a live form, just with some of the data fields populated. Again, possible with XML merge in Acrobat Pro, but a 2 stage process that requires £300 of software to complete.....

The following example from the itext website seems to make it MUCH simpler than you have demontrated
It is possible for you to look at a demonstration and technique that is easy to replicate with a -- data is here, form fields are there, connection is possible, please can I get a partially filled form ready to attach to an email and send out model -- rather than the very very clever, ridiculously talented, but impossible to replicate one you have here.

Having paid the money and taken the time to watch the videos I am now further from a solution, which does appear on the surface to be potentially simpler and very rewarding.

Cant post example code but it is under questions, filling pdf forms...

Have been through the file in detail and understand most of what is happening in theory.

So I have bought the book and am trying to do just a simple example from it
Can you see any reason why the following would not work???

Have tried it with forward slash and backslash in the path and still an error is returned...

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import org.apache.commons.codec.binary.*;

try {
PdfReader reader;
PdfStamper stamper;
AcroFields form;
reader = new PdfReader("E:\HelloWorldForm.pdf");
stamper = new PdfStamper(reader, new FileOutputStream(
"E:\HelloWorldFilledInForm.pdf"));
form = stamper.getAcroFields();
form.setField("Who", "john");
stamper.close();

} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}

Hi

Wondering if enough time has passed.
"Maybe in a few months. Do you personally need the ability to extract data from PDF forms?"
Would love to be able to do this...

Stephen

Has anyone been able to get this to work under Windows? I'm using FIlemaker 11 on Windows 7 with Java 1.6.0_24, and when I try to generate the PDF using the technique file, it displays the 'Error Log' layout with no errors listed. Stepping through the scripts, it is getting as far as running the groovy script in PDFForm.PopulateFinish, but when it checks the $formFieldsMissing variable after that call, it has a value of 'ERROR' and the groovy script hasn't generated the filled PDF file.

It runs great on the Mac, and I had put a couple days of work into integrating it into my solution before I discovered that it doesn't work on Windows.

I figured out my problem running the solution on Windows. I was running Windows under VMWare, so my desktop path was something like \\vmware-host\Shared Folders\Desktop. The scripts retrieve this path as a Filemaker path (e.g. filewin://vmware-host...) and use it to find the PDF Forms Output folder. Before calling Groovy, PopulateFinish uses Filesystem.SetPathToReg to convert this to a normal OS path and that function includes a step to trim both leading and trailing slashes. The Groovy script was blowing up because the path was missing the leading UNC path characters ('\\'). I changed Filesystem.SetPathToReg to only trim trailing slashes, and everything works now.

We are a small company with Filemaker server software. I'm using Filemaker pro 11 on my PC. When downloading itext it's not loading onto my computer it just downloads a folder onto my computer. If I need to place the info into a folder, like the directions say, I have no idea how to find the folder. I also do not know how it will work because PC usually needs the program to be loaded on the computer.

I have followed the instructions to the letter but I get an error with no error listed in the log. I am really a newbie at using filemaker and I was hoping that this could be adapted to a simple solution I could use to populate pdfs from a database. I am using windows and was wondering if this problem is only experienced by folks running windows? Any help would be very much appreciated.

can someone explain to me what the SMSetVariable ( "fm_timestamp" ; Get ( CurrentHostTimestamp ) ) is doing? I tried using the SMGetVariable ( "fm_timestamp" ) but it returned an error. Whats this doing and how or when do i use it?

Mark Johnson
On Hold Company
mark@onholdcompany.com
800-492-9030 Ext 103

Mark Johnson
Aroma Impressions
mark@aromaimpressions.com

Just subscribed today, although it was only to look at these videos, which seem to no longer be available. Also zip doesn't seem to work with FM 12. Moans about the iText.jar and commons-codec.jar being out of date. Downloaded latest versions, but it doesn't seem to like them. Also downloaded latest script master.

Any thoughts/help greatly appreciated.

Guy

The technique of using iText still works, it's just that technology has moved forward. You would have to take what is talked about in the videos and adapt or modify to the newer versions of iText.

I have a developer friend who very much uses iText and ScriptMaster in order to make this happen within FileMaker.

While I can't offer an updated video and sample file I can say it still works. I've also updated the links for the videos and fixed them. They were broken in the move to the newer site.

Matt

-- Matt Petrowsky - ISO FileMaker Magazine Editor

Matt,

It would be pretty nice to see a working update on this.

Are there any videos associated with this? I just paid for this and nothing useful. Will be asking for a refund.

NDM