Copy link to clipboard
Copied
This is a basic question but I can't find the answer. I am running a script from one pdf and want to change a field in another pdf. To refer to the main pdf, I used something like
var mainDoc=this;
How do I set a variable to refer to the other pdf?
Originally, I used :
var otherDoc = app.openDoc("second.pdf", mainDoc);
This all worked well but it doesn't work on Reader XI, possibly because protected mode is on and I can't turn it off because it's a computer network at my workplace. I'm trying to work around it by opening the second pdf manually and having it open while I trigger the script from the main pdf. But it's not doing anything.
Thanks!
Ah OK, the title is not really important. Look at the path property.
If the activeDocs method is returning your document then you can access it like this, for example:
var otherDoc = activeDocs[1];
A better way would be to search the array for the document that has the file-name you're interested in, though.
Copy link to clipboard
Copied
From the documentation of the openDoc method:
Returns
A Doc object or null:
● In Acrobat 5.0, this method returns a Doc object.
● In Acrobat 5.0.5, the method returns the Doc object unless the disclosed property of the target
document is not true, in which case it returns null.
● Beginning with the Acrobat 5.0.5 Accessibility and Forms Patch and continuing with Acrobat 6.0 and
later, openDoc behaves as follows:
● During a batch, console or menu event, openDoc ignores the disclosed property and returns the
Doc object of the file specified by cPath.
● During any other event, openDoc returns the Doc, if disclosed is true, and null, otherwise.
In other words, the file has to be disclosed for this method to return a reference to it.
Copy link to clipboard
Copied
PS. I moved your question to the JavaScript forum.
Copy link to clipboard
Copied
Thanks for the reply but I have disclosed the file. This was all working on an older version of Reader
Copy link to clipboard
Copied
Then it's probably caused by the Protected Mode, yes. The only way I can think of around that (possibly) is to access the document via the app.activeDocs array. Have you tried that?
Copy link to clipboard
Copied
Yes. For some reason, it doesn't see the two PDF files that are open but it does recognise a Word document that isn't open. ?!?
Copy link to clipboard
Copied
That's impossible. You need to provide more details as it seems we're talking about two very different things here...
Copy link to clipboard
Copied
I tried it again. It wasn't quite doing what I thought it was -
To test the concept, I used :
var d=app.activeDocs;
for (var i=0;i<d.length;i++){
app.alert(d.info.Title);}
Two PDFs were open - the main.pdf and second.pdf
The alert output was "Microsoft Word - second.docx", which is the name of the original Word document that I created and then saved as a PDF. Any other PDF I open results in a blank alert.
Is there a way of just saying
var otherDoc="second.pdf";
That doesn't work because it thinks that "second.pdf" is a string. But is there something like that that would work?
BTW, thanks very much for taking the time to look at this
Copy link to clipboard
Copied
Ah OK, the title is not really important. Look at the path property.
If the activeDocs method is returning your document then you can access it like this, for example:
var otherDoc = activeDocs[1];
A better way would be to search the array for the document that has the file-name you're interested in, though.
Copy link to clipboard
Copied
Great! That's what I needed. Thanks very much
Copy link to clipboard
Copied
The title isn’t really the problem but if you want to see what is happening you need to realise that the title is just a string and not the file name. File > Properties will show you the title, which must be the string ending .docx.