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

Insert a PDF into another PDF - every other page

Community Beginner ,
Feb 24, 2017 Feb 24, 2017

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

TOPICS
Acrobat SDK and JavaScript , Windows
3.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

correct answers 1 Correct answer

Community Expert , Feb 24, 2017 Feb 24, 2017

This is correct. In the console select the whole code and press Ctrl-Enter.

Translate
Community Expert ,
Feb 24, 2017 Feb 24, 2017

What happens when you run the code? Is there an error message? If so, what does it say?

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 ,
Feb 24, 2017 Feb 24, 2017

Thanks - I get this:

#

SyntaxError: syntax error

1:Console:Exec

undefined

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 ,
Feb 24, 2017 Feb 24, 2017

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.

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 ,
Feb 24, 2017 Feb 24, 2017

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!

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 ,
Feb 24, 2017 Feb 24, 2017

What code do you use now?

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 ,
Feb 24, 2017 Feb 24, 2017

for (var i=this.numPages-1; i>=0; i--)     if (i % 2 != 0) this.insertPages(i, "/c/temp/FileToInsert.pdf");

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 ,
Feb 24, 2017 Feb 24, 2017

This is correct. In the console select the whole code and press Ctrl-Enter.

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 ,
Feb 24, 2017 Feb 24, 2017
LATEST

Ahh, user error! Thank you so much all, I really appreciate the help!

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 ,
Feb 24, 2017 Feb 24, 2017

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

    }

}

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 ,
Feb 24, 2017 Feb 24, 2017

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

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