Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Take a look at this post:
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
 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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ohh. Sorry. Yes, it was misunderstand. I forgot to write that I tried also that. In documentation there is example for that.
If I try this...
var doc = app.openDoc("1.pdf");
app.alert(doc.getField("Text1").value);
First line will open the 1.pdf document but the message will not be executed. Why?
but...
var doc = app.openDoc("1.pdf");
app.alert("blabla");
Both lines will be executed.
Copy link to clipboard
Copied
Pls take a look at the example from the documentation
This is my original code
oDoc = app.openDoc({
cpath:"1.pdf",
bHidden:true
});
var v = oDoc.getField("Text1").value;
this.getField("Text1").value = v;
oDoc.closeDoc();
but not working... Do you know why?
Copy link to clipboard
Copied
Here is a tutorial on using the console window:
https://www.pdfscripting.com/public/images/video/AcroJSIntro/AcroJSIntro_ConsoleWindow.cfm
Copy link to clipboard
Copied
var doc = app.openDoc("1.pdf");
app.alert(doc.getField("Text1").value);First line will open the 1.pdf document but the message will not be executed. Why?
By @Deleted User
The probable reason the second line isn't run is that Acrobat throws an exception on the first line. This is the importance of looking in the console window. It will show any uncaught exceptions.
Copy link to clipboard
Copied
In your original code "cpath" is spell incorrectly. JavaScript is a case sensitive language, so it's "cPath"
Here is the correct code:
oDoc = app.openDoc({
cPath:"1.pdf",
bHidden:true
});
However. your paths are not complete. You would be better served to use fully qualified file paths.
This is also the type of thing that will cause Acrobat to throw an exception.
Copy link to clipboard
Copied
Oh god... I didn't notice that. Yes, I know that some languages are case sesitive becase I work with C and C++. I don't have any experience with Java Script. This is my first project - I need to do some automation for a few PDF documents that share the same data.
var oDoc = app.openDoc({
cPath:"C:/Users/Administrator/Desktop/1.pdf",
bHidden:true
});
var v = oDoc.getField("Text1").value;
this.getField("Text1").value = v;
oDoc.closeDoc();
I looked at the Debuger and getting this error.
TypeError: oDoc is undefined
5:AcroForm:Button1:Annot1:MouseEnter:Action1
I really do not understand why it report that oDoc is undefined. This code open the reqired file but don't read value of required field.
Copy link to clipboard
Copied
I found this post on the forum related to this error
https://community.adobe.com/t5/acrobat-discussions/app-opendoc-return-typeerror-otherdoc-is-undefine...
In documentation
I added that line as first line in the script. I have the same error.
this.addScript("Disclosed", "this.disclosed = true;");
var oDoc = app.openDoc({
cPath:"1.pdf",
bHidden:true
});
var v = oDoc.getField("Text1").value;
this.getField("Text1").value = v;
oDoc.closeDoc();
Copy link to clipboard
Copied
Open the document.
In the Javascript console execute:
this.disclosed = true;
Save the document.
Copy link to clipboard
Copied
I did that.
NotAllowedError: Security settings prevent access to this property or method.
Doc.disclosed:1:Field Button1:Mouse Enter
Copy link to clipboard
Copied
Use the Javascript console:
Copy link to clipboard
Copied
You need to place that code as a doc-level script, not run it from a button.
Copy link to clipboard
Copied
So you've already seen that the "app.openDoc" only returns the document object when run from a privileged context, or if the document is disclosed, i.e., the document being opened is already disclosed.
So, as pointed out by Try67, the document being opened must have a document level script that sets the disclosed property to true. The document has to have been setup with this script before it is opened from the script in the button. This is I believe the final issue with your code.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now