Skip to main content
January 11, 2024
Question

JavaScript for Acrobat get filed value from another file pdf

  • January 11, 2024
  • 2 replies
  • 3077 views

I have struggled to read the value from the form filed in doc1 and write in another field in doc2

 

I have two pdf document, for example:

 

doc1:

Text filed with name Text1

Text filed with name Text2

Button  filed with name Button1

doc2:

Text filed with name Text1

Text filed with name Text2

 

doc1, mouse enter event on Button1, action Run a java script 

var doc = app.openDoc("doc2.pdf", bHidden) ;
getField("Text1").value = doc.getField("Text1").value;

 

this code not working

 

If I try to copy data from one text field to another in the same pdf document that works

getField("Text1").value = doc.getField("Text1").value;

 

My question is how I can read text field value from doc2 and copy it into text field in doc1?

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
January 11, 2024

in this code

var doc = app.openDoc("doc2.pdf", bHidden) ;
getField("Text1").value = doc.getField("Text1").value;

 

the bHidden value is not specified.  

Did you check the console for errors?

 

 

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

 How is not specified? 🙂 Look at documentation. Lines are OK! They works without any errors. I can read value of any field and write it to another in the same doc. That not working with two different documents. openDoc opet pdf in show/hidden state but it seems that getField not working on ref document

Thom Parker
Community Expert
Community Expert
January 12, 2024

You misunderstand.  In the script you posted, the value of the bHidden variable is not set.   

 

Also you haven't said if any errors were reported in the JavaScript console (Press Ctrl-j).  

I strongly suspect the "app.openDoc()" function is throwing an exception because the 2nd argument for this function is a document object that is used to resolve a relative path.  The "bHidden" argument is the 4th input. So Acrobat is likely choking on the 2nd input, which is the bHidden variable. Please refer to the reference entry you've posted above. 

 

I think what you meant to write was this:

 

var doc = app.openDoc({cPath:"doc2.pdf", bHidden:false}) ;

 

The Acrobat model allows some function arguments to be passed by object, using named parameters. Some functions in the model have huge numbers of entries, and this notation provides a method for entering only the needed arguments. 

 

 

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