Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to duplicate certain pdf page between each pages

Participant ,
Aug 27, 2024 Aug 27, 2024

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

 

TOPICS
JavaScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Aug 27, 2024 Aug 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)
}

 

 

 

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2024 Aug 27, 2024

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);

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2024 Aug 27, 2024

Any help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2024 Aug 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)
}

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2024 Aug 27, 2024

I tried to make as you said but this errors appeared

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2024 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2024 Aug 27, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2024 Aug 27, 2024

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);

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2024 Aug 27, 2024

I am very grateful .

Thank you very very much

-----------------------------

Can you see a private messages please 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 03, 2024 Sep 03, 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)

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 03, 2024 Sep 03, 2024
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines