Skip to main content
Flipside32
Participating Frequently
March 3, 2020
Answered

Mirroring a field from an attached PDF using JS

  • March 3, 2020
  • 2 replies
  • 1017 views

Hello all! 

 

I have a fillable form with an attached pdf file. Rather than the user having to enter the same information (i.e. name, title...etc.) Is it possible for the data fields to mirror each other from one PDF to the attached PDF? maybe using javascript? 

 

Thank you in advance! 

This topic has been closed for replies.
Correct answer Thom Parker

Yes, there are a few different ways to approach a solution.

If the scripts have to be on the PDF, then a script on the main doc can acquire field values from an attached file, or write values to an attached file. It doesn't work the other way around when you are doing this directly thru the doc objects because an embedded file doesn't know who it's parent is, or have the abilty to directly access it. 

But the main file can open an attachement PDF with

"Doc.openDataObject()". 

This opens the attached file as hidden. The user doesn't see it, but its visible to JavaScript for accessing the fields. 

Here's the reference entry:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FDoc_methods.htm%23TOC_openDataObjectbc-78&rhtocid=_6_1_8_23_1_77

 

This type of scirpt best placed in a button on the main PDF.

 

Another method is to write data to a common location, where the other file can read it. This is not as easy as it used to be from a document script. But I still think there are some gobal objects that will work for his, such as the color object. Again this type of script is best placed in a button the user presses to update data.

 

 

 

2 replies

Flipside32
Participating Frequently
March 5, 2020

Thank you so much! Thom! i"m gonna try this today. 

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
March 3, 2020

Yes, there are a few different ways to approach a solution.

If the scripts have to be on the PDF, then a script on the main doc can acquire field values from an attached file, or write values to an attached file. It doesn't work the other way around when you are doing this directly thru the doc objects because an embedded file doesn't know who it's parent is, or have the abilty to directly access it. 

But the main file can open an attachement PDF with

"Doc.openDataObject()". 

This opens the attached file as hidden. The user doesn't see it, but its visible to JavaScript for accessing the fields. 

Here's the reference entry:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FDoc_methods.htm%23TOC_openDataObjectbc-78&rhtocid=_6_1_8_23_1_77

 

This type of scirpt best placed in a button on the main PDF.

 

Another method is to write data to a common location, where the other file can read it. This is not as easy as it used to be from a document script. But I still think there are some gobal objects that will work for his, such as the color object. Again this type of script is best placed in a button the user presses to update data.

 

 

 

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