Copy link to clipboard
Copied
I have a 2000+ page document that I am trying to insert another PDF after every second page. I'm a Javascript novice and I've managed to get this far. Can anyone offer any advise as to what I'm doing wrong?
for (var i=this.numPages-1; i>=0; i--) { if (i % 2 == 0) { { this.insertPages(i, "FileToInsert.pdf"); }
This is correct. In the console select the whole code and press Ctrl-Enter.
Copy link to clipboard
Copied
What happens when you run the code? Is there an error message? If so, what does it say?
Copy link to clipboard
Copied
Thanks - I get this:
#
SyntaxError: syntax error
1:Console:Exec
undefined
Copy link to clipboard
Copied
Use something like this:
for (var i=this.numPages-1; i>=0; i--)
if (i % 2 != 0) this.insertPages(i, "/c/temp/FileToInsert.pdf");
You must adjust the path of the file.
Copy link to clipboard
Copied
I've tried adusting the file path (and placing it into my temp folder, but I still get this result:
SyntaxError: syntax error
2:Console:Exec
undefined
Thanks for trying!
Copy link to clipboard
Copied
What code do you use now?
Copy link to clipboard
Copied
for (var i=this.numPages-1; i>=0; i--) if (i % 2 != 0) this.insertPages(i, "/c/temp/FileToInsert.pdf");
Copy link to clipboard
Copied
This is correct. In the console select the whole code and press Ctrl-Enter.
Copy link to clipboard
Copied
Ahh, user error! Thank you so much all, I really appreciate the help!
Copy link to clipboard
Copied
The path is fine as long as the file to insert is located in the same folder as the file to insert to. The problem is a syntax one. You had the curly brackets placed incorrectly. Use this code:
for (var i=this.numPages-1; i>=0; i--) {
if (i % 2 == 0) {
this.insertPages(i, "FileToInsert.pdf");
}
}
Copy link to clipboard
Copied
Thanks Try67, I still seem to have a syntax error:
for (var i=this.numPages-1; i>=0; i--) {
if (i % 2 == 0) {
this.insertPages(i, "FileToInsert.pdf");
}
}
SyntaxError: missing } in compound statement
2:Console:Exec
undefined
Find more inspiration, events, and resources on the new Adobe Community
Explore Now