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

Javascript syntax error - moving pages

New Here ,
Dec 11, 2023 Dec 11, 2023

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

    }

}

```

 

 

 

janee_0-1702295229317.png

 

TOPICS
JavaScript

Views

441

Translate

Translate

Report

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

Copy link to clipboard

Copied

@BDA111 

 

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

 

Jane

Votes

Translate

Translate

Report

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
New Here ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

Thank you!

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

The characters at

  ```javascript

are illegal.

Votes

Translate

Translate

Report

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
New Here ,
Dec 11, 2023 Dec 11, 2023

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

What error message does you get?

Votes

Translate

Translate

Report

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
New Here ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

The same one:

 

SyntaxError: syntax error
1:Console:Exec
undefined

 

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

No. Why have you added this?

Votes

Translate

Translate

Report

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
New Here ,
Dec 11, 2023 Dec 11, 2023

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Remove those lines before executing the code.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
New Here ,
Dec 13, 2023 Dec 13, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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