Skip to main content
Inspiring
August 27, 2024
Answered

Script to duplicate certain pdf page between each pages

  • August 27, 2024
  • 2 replies
  • 2542 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)
}

 

 

 

 

Participant
September 3, 2024

Would this script be the only thing I need to enter to accomplish duplicating a page wihtin a single PDF using a button.

 

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

 

PDF Automation Station
Community Expert
Community Expert
September 3, 2024

No.  i and pth are variables that first must be defined.  You can't run it from a button because the accessing the file system to get the page from the source PDF is privileged so you would have to created a trusted function in a folder level script and call that function from the button.

Inspiring
August 27, 2024

Any help