Skip to main content
Inspiring
November 29, 2017
Answered

What is the best way to move multiple pages around in a document?

  • November 29, 2017
  • 2 replies
  • 1332 views

I'm attempting to automate a timely monthly task that involves taking many pdfs (A, B, C, etc), combining into one document, and then sorting the pages. It is the same order every month, but there is no method for how the pages are sorted.

For example, the combined document is in the order

1: A pg1

2: A pg 2

3: A pg 3

4: A4

5: B1

6: B2

7:  B3

8: C1

9: D1

10: D2

I need the order to be

1: A1

2: A2

3: D2

4: B1
5: B2

6: A4

7: B3

8: C1

9: A3

10: D1

The only idea I have is this.movePage(9,2); and so on...but that is rather clumsy and would require a pretty intense set up for the 160 pg document...

I'm new to JavaScript and Acrobat, so any advice is greatly appreciated!

This topic has been closed for replies.
Correct answer ed_101

No, should work just fine. Just keep in mind that the page numbers change after each insertion, if you inserted the new pages before them. For example, after the first line is executed what was page 5 is no longer page 5, but now page 8, because you inserted 3 new pages before it...


Thank you for your help.

For others who come across this thread with a similar question, this what I ended up doing:

I had one folder that contained all PDFs I would be working with.

I started with the pdf that contained the cover page open, then ran a script that added in the pages of the other PDFs as suggested.

I ended up using some variation of "this.insertPages." [It is essential to know what would typically be considered page 1, in this context, is page 0, and to insert something before the first page reference -1].

to insert 1 single page of a multi-page document: this.insertPages({nPage:3, cPath: "name1.pdf", nStart:0}); [this inserts one page from the document name1, starting at 0(which is page 1), placing that 1 page after page 3 (which is page 4) in the current document]

to insert an entire document: this.insertPages({nPage:0, cPath: "name2.pdf"}); [this inserts the entire document name2 after page 0 (which is page 1) in the current document]

to insert multiple consecutive pages of a document (but not the whole thing): this.insertPages({nPage:4, cPath: "name3.pdf", nStart:4, nEnd:7}); [this takes pages 4-7 (which is really pages 5-8) of the document name3 and inserts it after page 4(which is page 5) in the current document].

2 replies

try67
Community Expert
Community Expert
November 29, 2017

From my experience the easiest way is to create a new file and insert the

pages into it, in the desired order.

ed_101Author
Inspiring
November 29, 2017

Unfortunately the existing PDFs are already multiple pages that are not in the order needed, so that would require breaking the 26 pdf files into individual pages.

Have you done it before from a similar starting point?


Thanks!

Thom Parker
Community Expert
Community Expert
November 29, 2017

This is the JavaScript Forum, so breaking up a document and putting it back together again isn't a big deal On this forum we're talking about doing it programatically, not manually.

The technique is to create a new PDF, then move pages from the old doc, to the new. From here you can overwrite the old doc, or just name it the same with something like "_newPageOrder".  You can do it in-place, but this requires a lot of managing page numbers, because they change as you move things around.

Assembling a new PDF from pages of other PDFs is similar.

For either scenario you need a Page Order list.  I've done both of these applications more than once, a CSV file works nice, but all you really need is a plain text listing of the page numbers.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
November 29, 2017

I actually wrote a tool for this. It is not yet available on my web site PDFScripting.com, but contact me if you are interested.  Its a non-trivial task

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often