Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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)
}
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Any help
Copy link to clipboard
Copied
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)
}
Copy link to clipboard
Copied
I tried to make as you said but this errors appeared
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
I am very grateful .
Thank you very very much
-----------------------------
Can you see a private messages please
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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.

