Skip to main content
boilermaker73
Inspiring
January 2, 2024
Question

Assign/copy a text field value from one PDF to another containing a text field with the same name

  • January 2, 2024
  • 1 reply
  • 2138 views

Given an interactive PDF form containing a text field used to store a JSON (string) object containing data to populate form fields, I am looking for an alternative method (as opposed to requiring the end user to resort to cut and paste) to copy the JSON (string) data to a text field of the same name into an updated (renamed) version of the PDF form. To this end, I would prefer adding a menu item to my existing popup menu to activate a custom script to perform this task in one click of the mouse. All considered, what would be the best way to accomplish this task, i.e., using a global variable, import/export methods, from inside a custom script? Thank you ahead of time. Oh, lest I forget, any javascript method used needs to be supported using the Free Adobe Reader version 20 or greater. Thank you ahead of time.   

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
January 2, 2024

A script on one PDF can access a form field in another PDF, if the target PDF is "disclosed", i.e., the "doc.disclosed" property is set to true.

A global variable won't work when used from a document script, unless the user has JS security for globals turned off, because only the document that sets the global can see it. 

Alternatively you can use a trusted folder level script to do this.

I have a paid for tool that does just this. Although it copies all data in matching fields, you could modify it for just the one field.

https://www.pdfscripting.com/public/Copy-Form-Data-Between-PDFs-Description.cfm

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
boilermaker73
Inspiring
January 2, 2024

Thank you Thom for the quick response. In reality, I was hoping you would be the one to respond to my post. Also, thank you for providing the paid tool. I will be sure to check it out since I am not looking to reinvent the wheel. Also, am I correct in assuming that your paid tool doesn't require a folder level script to be installed on the end user's computer in order to use the script added to the PDF form? Last but not least, Happy New Year to you and your family. 

boilermaker73
Inspiring
January 5, 2024

In electing to review the script one last time, it appears that I may have been overthinking the script required to copy a field value from one PDF to another with identical named fields. Given the script required to accomplish this task provides the same end result as having two PDF forms open inside Acrobat using basic cut and paste procedures, and moving from one PDF to the other, a task I would prefer to accomplish using a script activated through a popup menu item,  I believe the script shouldn't be much different than copying a form field value from one form field to another inside one and the same PDF form other than in this particular instance, the script is intended to copy a form field value to a form field of the same name residing in another PDF form. Alas, I suspect the script isn't at fault but that security measures added by Adobe to date appear to be interfering with the exceutiuon of a certain Acrobat method, app.openDoc, used in my script that in turn prevent the script from performing as intended. This being the case, I believe I would be better off instructing my end user to have both PDF forms (older and updated PDF forms to which I have already set the disclosed property to true) open in Acrobat, as oppposed to using the app.openDoc method to open the updated PDF to which the form field value from the older version needs to be copied, and using a script to loop through and retrieve each active doc by title to copy a form field value from one PDF to the other PDF. Question is, might I anticipate security issues using this alternative method? Also, as the form fields copied to/from are of the same name inside each PDF, what method, if any, may be required to change an already open PDF doc to the active doc for copying a like named field value to/from another.  Thank you ahead of time.