Javascript syntax error - moving pages
Copy link to clipboard
Copied
Hello, I try to add a script for movin pages in Acrobat Pro and still get a syntax error. It should take the first page of the second half of the document and put it behind the first page of the first half of the document, the second one from the second half behind the second from the first half etc.
Could someone look at the script and tell me what is wrong with it, please? Thank you.
```javascript
var doc = this;
var numPages = doc.numPages;
// Ověření, že celkový počet stránek je sudý
if (numPages % 2 !== 0) {
console.println("Dokument musí mít sudý počet stránek.");
} else {
var halfNumPages = Math.floor(numPages / 2);
for (var i = 0; i < halfNumPages; i++) {
var targetPage = (i * 2) + 1;
doc.movePage(halfNumPages + i, targetPage);
}
}
```
Copy link to clipboard
Copied
I've moved your post to the Adobe Acrobat Pro forum and added the topic "JavaScript" for you.
Jane
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
You're welcome @BDA111 , we are happy to move posts to the place where they are most likely to get help. Welcome to the Community Forums!
Jane
Copy link to clipboard
Copied
The characters at
```javascript
are illegal.
Copy link to clipboard
Copied
Thank you, but I get a syntax error on the second row as well, the text "var doc = this;" is illegal too according to it.
Copy link to clipboard
Copied
What error message does you get?
Copy link to clipboard
Copied
The same one:
SyntaxError: syntax error
1:Console:Exec
undefined
Is the text "```javascript" necessary anyways?
Copy link to clipboard
Copied
No. Why have you added this?
Copy link to clipboard
Copied
I did not, AI did 😄 I'm not a programmer, unfortunataly. It looks kinda weird to me so I asked if it's correct and it told me that it's a mistake, that it is used in some markedown coding to mark the beginning and the end of the code.
Copy link to clipboard
Copied
Remove those lines before executing the code.
Copy link to clipboard
Copied
Also remove this line:
var numPages = doc.numPages;
It doesn't make any sense and just causes a conflict between a variable and the built-in property with the same name.
Copy link to clipboard
Copied
PS. I'm not sure the logic of this code is correct, but if you make those changes at least it will run and do something...
Copy link to clipboard
Copied
I did not, AI did 😄 I'm not a programmer
By BDA111
AI cannot come anywhere close to "creating" code written by those who take the time and effort to learn it.
Jane
Copy link to clipboard
Copied
Guys, you would be surprised, i deleted the first and the last line and it worked. Needed to do some small edits to move the pages properly and it's done.
Thank you so much for your time and effort! 🙂

