Copy link to clipboard
Copied
Yes I know this has been a major discussion in the past, but I couldn't find a proper solution, mostrly because in the replies I've read there were links which point to nowhere or expired.
Whatever, I'm trying to figure out a JS to add as action to a button that, basically merge the document from which I'm working to another document. The document is variable, in fact it depends by a value reported into a specific text field in my document. I tried to accomplish this using the following Code, but it never worked, it's just opening the other document in a different window:
var textValue = this.getField("TEXTFIELD").value;
var filePath = "G:\\Il mio Drive\\@@@@@@@@\\PASSPORT " + textValue + ".pdf";
var externalDoc = app.openDoc(filePath);
if (externalDoc != null) {
this.insertPages({
nPage: this.numPages,
cPath: filePath,
nStart: 0,
nEnd: externalDoc.numPages - 1
});
externalDoc.closeDoc(true);
} else {
app.alert("Impossibile aprire il documento esterno.");
}
Any help will be much appreciated
Copy link to clipboard
Copied
Several issues there:
- The file paths needs to be in the following format:
"/G/Il mio Drive/@@@@@@@@/PASSPORT " + textValue + ".pdf";
- You must use the reference to the file you opened, ie. externalDoc, instead of the "this" keyword.
- The file you open must be disclosed for openDoc to return a reference to it.
- You must run both openDoc and insertPages from a privileged context, such as a trusted function in a folder-level script.
- You must save externalDoc before closing it if you want anything you did to it to not go away...
Copy link to clipboard
Copied
Thank you for your comment.
Please help me a little bit further here:
- The file paths needs to be in the following format:
"/G/Il mio Drive/@@@@@@@@/PASSPORT " + textValue + ".pdf";
Yes that is the path when I copied from the file, but when it comes to re-writing it in Javascript I had always to use \\ rather than /
- You must use the reference to the file you opened, ie. externalDoc, instead of the "this" keyword.
Please clarify
- The file you open must be disclosed for openDoc to return a reference to it.
The file from which I'm operating is disclosed, but the files I call with openDoc are not and it worked for the simple function to just open them in another window
- You must run both openDoc and insertPages from a privileged context, such as a trusted function in a folder-level script. Please clarify. I had just put both the folders with the files I'm working on it as Trusted paths in Acrobat
- You must save externalDoc before closing it if you want anything you did to it to not go away...
Copy link to clipboard
Copied
- No, you must use the path as I wrote it. With forward slashes, not escaped back-slashes.
- For example, replace this:
this.insertPages({ ...
With:
externalDoc.insertPages({ ...
- If you open a file with openDoc and want to do anything with it, beyond just displaying it on the screen, it must be disclosed.
- Not sure if placing the folders as trusted will be enough, but we can check that later. First fix the other issues and then try it again.
Copy link to clipboard
Copied
I did the changes you suggested but I obtain a different result. It just skips to another document open already
Copy link to clipboard
Copied
When you open a file it will gain focus, yes, that is normal.
Copy link to clipboard
Copied
But that is not the file supposed to open, it's another random form that I had opened already for other purposes
Copy link to clipboard
Copied
That doesn't make sense. Files don't just open of their own accord.
Copy link to clipboard
Copied
It doesn't, I'm just saying the form isn't opening or merging with the form requested, it simply shift to another form open but I don't think it's because it's setting the focus to the other form, it just doesn't do what I'm hoping to do. While I do thank you for your patience, May I simply ask to provide with a draft of the Code as you'd write it ?
Copy link to clipboard
Copied
Try this:
Execute the script in the Javascript console.
Copy link to clipboard
Copied
You mean like when I declare the forms disclosed = true ?
Copy link to clipboard
Copied
Yes
Copy link to clipboard
Copied
I've not been able to do it. However I have this Code now, which is not working either.
RaiseError: Si è verificato un errore in un file.
var shipsName = this.getField("SHIPSNAME").value;
var path = "G:\\@@@@\\@@@\\" +shipsName;
var files = {
"Check Box1": path+ "\\COR.pdf",
"Check Box2": path+ "\\CREW.pdf",
"Check Box3": path+ "\\GUEST.pdf"
};
for (var checkbox in files) {
if (this.getField(checkbox).value === "Yes") {
this.insertPages({
nPage: this.numPages - 1,
cPath: files[checkbox]
});
}
It gives me this kind of mistake
Doc.insertPages:19:Field Button4:Mouse Up
===> Si è verificato un errore in un file.
Copy link to clipboard
Copied
- You did not adjust the file paths as I've suggested.
- You've declared a variable which has the same name as a built-in property of the Document object (path). That will cause a conflict. Rename it to something else.
Copy link to clipboard
Copied
Like this?
var shipsName = this.getField("SHIPSNAME").value;
var pat = "G:/________/_________/" +shipsName;
var files = {
"Check Box1": pat+ "/COR.pdf",
"Check Box2": pat+ "/CREW.pdf",
"Check Box3": pat+ "/GUEST.pdf"
};
for (var checkbox in files) {
if (this.getField(checkbox).value === "Yes") {
this.insertPages({
cPath: files[checkbox], nPage: -1});
}
}
Copy link to clipboard
Copied
Not quite. See the example in my first reply.
Copy link to clipboard
Copied
Anyaway I'm still having issue due to "Raised Error etc.etc.". I used a simple Code this.insertPages with other forms from the Console and it worked. SO I tried to make my code a trusted function, but it didn't work either
Copy link to clipboard
Copied
Your code doesn't include any references to a trusted function. You can't use it in its current form from a button. It has to go through a trusted function, located in a folder-level script file.
Copy link to clipboard
Copied
At last I found the way: 1. Create the trusted function and put the entire JS into the Javascript Folder 2. change settings in Acrobat both regarding advanced security and Javascript 3. Recall the trusted function through a simple button that I needed to have into my Doc.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more