Skip to main content
Participant
July 11, 2024
Question

Merge multiple PDFs in exact order

  • July 11, 2024
  • 2 replies
  • 384 views

Hello,
I have 4 PDFs that I am trying to merge with an exact order. Each PDF is about 500 pages (PDF A, PDF B, PDF C and PDF D. I would like to insert _Example: Page 1 of PDF A, then Page 1 of PDF B, then Page 1 of PDF C, then Page 1 of PDF D, then Page 2 of PDF A, then Page 2 of PDF B, then Page 2 of PDF C, then Page 2 of PDF D, and so on......

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
July 11, 2024

This requires a custom tool, but it's not too difficult. It could be done from a simple console script. 

Use the doc.insertPages function.  

Here's an outline. 

 

var cPathA = "... path to doc A";

var cPathB = "... path to doc B";

... etc. 

oNewDoc = app.newDoc();

var nInsertPos = 0;

for(var nPg=0;nPg<=MaxPages;nPg++)

{

     oNewDoc.insertPages(nInsertPos++, cPathA, nPg);

     oNewDoc.insertPages(nInsertPos++, cPathB, nPg);

  ... etc.

}

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
July 11, 2024

Create a one page blank PDF and open it.  Get the cPaths to the 4 PDFs and run this script in the console:

var pathA = "(…the path to PDF A…)";

var pathB = "(…the path to PDF B…)";

var pathC = "(…the path to PDF C…)";

var pathD = "(…the path to PDF D…)";

var pgs= (the number of pages in the largest PDF);

 

for(var i=0; i<pgs; i++)

{

try{ this.insertPages(this.numPages-1, pathA, i, i)}catch(e){};

try{ this.insertPages(this.numPages-1, pathB, i, i)}catch(e){};

try{ this.insertPages(this.numPages-1, pathC, i, i)}catch(e){};

try{ this.insertPages(this.numPages-1, pathD, i, i)}catch(e){};

}

 

Then delete the first page.