Skip to main content
Inspiring
August 27, 2024
Answered

Script to duplicate certain pdf page between each pages

  • August 27, 2024
  • 2 replies
  • 2557 views

Hi All

I have 2 pdf files , 1  and 2 .... each of them have 20 pages , the 20 pages of the second file are the same page ( duplicate ) , Is there a script or autoamtic method to place any page from the second pdf ( duplicated ) file between each pages of the first file ?

Thanks

 

This topic has been closed for replies.
Correct answer PDF Automation Station

Great thanks for you 

The script works like as charm

Please can you tell me what should I change if I want to to place 2 pages from the second file between every 2 pages in the first file or 3 pages ........ etc

Thanks


In the following line of the script:

this.insertPages(i,pth,0,0)

The 0,0 is a range of pages.  In this case it is page 1 to page 1 (page numbers are 0-based in JavaScript).  If you wanted to insert pages 1 and 2, you would change this line to:

this.insertPages(i,pth,0,1);

 

2 replies

PDF Automation Station
Community Expert
Community Expert
August 27, 2024

Yes.  First you need the path to the second PDF.  Open it and run the following script in the console, then copy the path it returns to the clipboard and close that PDF:

this.path;

Next, open the first PDF, and run the following script in the console after pasting the clipboard from the previous step between the quotes in the first line of this script:

 

var pth=""; //paste the path between the quotes to the left
for(var i=this.numPages-1;i>-1;i--)
{
this.insertPages(i,pth,0,0)
}

 

 

 

 

Inspiring
August 27, 2024

I tried to make as you said but this errors appeared

 

PDF Automation Station
Community Expert
Community Expert
August 27, 2024

Press Ctrl + k to open the preferences.  In the Security (Enhanced) category on the left,  make sure Enable protected mode at startup is not selected.  If it is selected, unselect it, restart Acrobat, and try again.

Inspiring
August 27, 2024

Any help