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

sintax error with insert pages

New Here ,
Mar 16, 2018 Mar 16, 2018

Copy link to clipboard

Copied

Hello all,

I wanterd to insert pages from one file into a mainfile, and this should be after every third page of the document.

I created this js:

this.insertPages({cPath:"Mainfile.pdf"});

var start = 4;

var jump = 3;

for (var i=start; i<this.numPages; i=i+jump) {this.insertPages (i);i++({cPath:"Insertfile.pdf"})}

But every time I want to run it, I get the error :

syntax error: missing; before statement 4, in Zeile5.

But I can't see any syntax error (I am not so good with js).

Could you please help me? Thanks

Christian

TOPICS
Acrobat SDK and JavaScript , Windows

Views

389

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
LEGEND ,
Mar 16, 2018 Mar 16, 2018

Copy link to clipboard

Copied

The last line is very weird indeed. Certainly wrong but I can’t understand what you wanted to do. For sure, the insertpages is finished by the ; so what is all that other stuff? And what do you expect

insertpages(i)

to do?

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 ,
Mar 16, 2018 Mar 16, 2018

Copy link to clipboard

Copied

Whenever I need to debug JavaScript problems, the first thing I do is to reformat the code so that blocks are getting correctly indented. This helps to spot some syntax problems. In your case, I am getting this:

this.insertPages({

  cPath: "Mainfile.pdf"

});

var start = 4;

var jump = 3;

for (var i = start; i < this.numPages; i = i + jump) {

  this.insertPages(i);

  i++({

  cPath: "Insertfile.pdf"

  })

}

As you may be able to see, there are some problems.

Based on your description, you are just trying to insert pages from a 2nd file - multiple times - into the first file. I see two instances of calls to Doc.insertPages() - one in line #1, and one in line #7. Is this really what you want?

When you look at lines 7 to 10, you will see that there is something wrong with your code. I assume you are trying to pass more than one argument to insertPages(), but that's not how it's done. Look at the documentation for this method: Acrobat DC SDK Documentation

You cannot mix straight parameters (i and i++) with the object syntax (cPath), it needs to be one or the other.

Also, your logic is wrong: When you insert e.g. a page after page 3, all of a sudden your document has one page more, which changes where you need to insert the next page. It is much easier to start from the back of the document and work your way down to the first page. This way, the page number of where you need to insert a page does not change based on how many pages you've already inserted. 

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 ,
Mar 16, 2018 Mar 16, 2018

Copy link to clipboard

Copied

LATEST

Thank you for your answer,

so I made this new script:

var start = 4;var jump = 3;

for (var i=start; i<this.numPages; i=i+jump)

this.insertPages({nPage:i,cPath:"Insertfile.pdf"})

and now its ok

(I counted the one page with the jump, so the page is insertet after every second page).

It is easyer for me to make it from the beginning, because there is a file with letters, they can be 1 page or more, and for every letter I need some pages like a description of the letter or a flyer, or something else. Or insert a second flayer between the letter and the first flyer...

I have found another script with a loop from the end, but its not so easy to set the last page to insert and then count back.

At least for me

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