Skip to main content
Participating Frequently
January 10, 2023
Question

Fillable Form to Flat PDF to Fillable Form Yikes!

  • January 10, 2023
  • 1 reply
  • 4081 views

Hello Everyone,

 

I hope you are all doing well.

 

I have been searching for an answer to my problem for weeks now, and decided to finally ask my question. First, I have a 4-page fillable form document. It’s my template and contains all the form fields I need. When it’s a completed form it’s saved as flattened PDF. I’m trying to find a way to return that flattened PDF to a fillable form again so that I can export the data values into a spreadsheet. I want to eventually use the form fields as variables in a statistical program. I get the point and click way of doing this. Prepare form > Merge Data files into spreadsheet, ect., but I would like to use an Action in Adobe Pro that included a few “Execute JavaScript” steps.

 

I am brand new to JavaScript and automation within Adobe Pro but I’ve been experimenting with different code to achieve a solution. I’m willing to write all the code I need, but what I’m looking for is sample script to draw from.

 

I have an action that inserts pages before the target document(s). I scoured the internet for the following code (thank you to the maker of this You Tube video and Action Step: https://www.youtube.com/watch?v=bhbU3C7RIpE) that then grabs all the form fields from this template document, and places them on the target document:

 

for (var p=0; p<this.numPages; p++) {

      for (var f = 0; f < numFields; f++)

    {

        name = getNthFieldName(f);

        type = getField(getNthFieldName(f)).type;

        rect = getField(getNthFieldName(f)).rect;

        var newField = this.addField(name, type, p, rect);

      

    }

}

Then I have step to delete the template. And another step to save the new target document. However, the resulting document is flawed. The target document has all the form fields from the template document but replicated on each page, so that each page contains all the form fields from the template document. This is not what I want.

 

If placed properly, it’s my belief that the form fields can tell JavaScript where to extract the data. Is this true? And if so, what would that code look like?

 

Also, not all the PDF forms are typed, but instead handwritten entries, so I know I will need an OCR step in an alternate Acrobat Action as well. What would be the best solution here? I feel that what I’m wanting is possible somehow, am I completely wrong? Please help!

 

Thank you so much,

JMagenta

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
January 10, 2023

- The easiest way to do it is just to take the original file and use the Replace Pages command to replace all the pages with those from the new version. That will keep all the existing fields in place.

- JS will not pick up the underlying text when you create a field over it. It can be done with a script, but it's a much more complicated task. You would need to use iterate over all the words in the page, comparing their locations on it with the area defined by the field's rect property.

- OCR in Acrobat is not going to pick up any hand-written text.

JMagentaAuthor
Participating Frequently
January 10, 2023

Thank you for your swift reply. I was afraid OCR wouldn't pick up any handwritten text. Thank you for that. Now that's a problem for another day. However, you're saying that if I just replace the pages of the target PDF with the template form it should pick up the fields? And what about the typed data in those fields, will it be available for export? 

Thom Parker
Community Expert
Community Expert
January 10, 2023

I understand. It's just what I'm left with right now. I can change the data into a word document that is editable. However, I can't seem to get to what I'm looking to achieve. Which is variables with unique values that are ready to be processed. 


If you know your users are going to be using Acrobat Reader, then you can use a script on the submit button to submit the data in a format that is good for Excel, such as simple XML.  

Read this article:

https://acrobatusers.com/tutorials/submitting-data/

And this:

https://www.pdfscripting.com/public/Form-Data-Handling.cfm

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often