Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript syntax error - moving pages

Community Beginner ,
Dec 11, 2023 Dec 11, 2023

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);

    }

}

```

 

 

 

janee_0-1702295229317.pngexpand image

 

TOPICS
JavaScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

@BDA111 

 

I've moved your post to the Adobe Acrobat Pro forum and added the topic "JavaScript" for you.

 

Jane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 11, 2023 Dec 11, 2023

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

The characters at

  ```javascript

are illegal.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 11, 2023 Dec 11, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

What error message does you get?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 11, 2023 Dec 11, 2023

The same one:

 

SyntaxError: syntax error
1:Console:Exec
undefined

 

Is the text "```javascript" necessary anyways?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

No. Why have you added this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 11, 2023 Dec 11, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

Remove those lines before executing the code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023
quote

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 13, 2023 Dec 13, 2023
LATEST

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! 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines