Skip to main content
Participant
January 20, 2020
Question

How can I make a single new .PDF out of many .PDF's 1st pages with javascript?

  • January 20, 2020
  • 2 replies
  • 316 views

Good Forum Folk,

 

  I wish to create a new .PDF composed of all the first pages of a large number of other .PDF's.  My preferred approach would be to create an Action with the "Default option:" of "Add folder..." as its first step.  At present I have the following javascript as my second step:

 

this.print(false,0,0,true);  [which sends p. 1 of the selected .PDF as a print job to the last-used printer]
this.closeDoc(true);        [which closes the selected document]

 

I would like to improve the script so that it only prompts to begin the process once (instead of for each .PDF included in the batch).

 

I look forward to your suggestions.

 

QD

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
January 20, 2020

One strategy is to create a PDF from first page of the first document processed, using the "doc.extractPages" function. Do not close this doc or extract it with a path. Instead, place the document object returned from extract pages into a global variable. Then for every document after that insert a page into the document. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
January 20, 2020

You can use the extractPages command to export the first pages to a single folder, and then manually combine all the files in that folder.

You do not need to add a closeDoc command to an Action. It does that automatically.