Skip to main content
gregorym17975653
Known Participant
July 16, 2021
Answered

Help with batching MULTIPLE pdf's into a SINGLE pdf using javascript?

  • July 16, 2021
  • 1 reply
  • 4572 views

Hi,

Need to create an automated way of using the Adobe Acrobat DC tool "Combine Files". Has anyone on this forum created a way to combine multiple PDF files into a single PDF? I suspect this is possible using javascript so any tips or tricks in this process is greatly appreciated.

Thanks in advance for your prompt reply.

-Greg

This topic has been closed for replies.
Correct answer bebarth

Hi Bebarth,

Yes, I am interested in how you do this? I should be able to easly create a file that includes a list of the filenames I want to process easily. Can you post your answer below this reply or e-mail your solution to me?

Thanks,
Greg


Hi,
All your files must be in the same directory.

Place the "Combine Files_BB.pdf" attached file in this directory then open it.

You paste the list of files in the left field then 2 solutions:

Either you copy the script of the right field then paste it in the console (then select all and "Enter") or you import the action wizard included in this file then run it.

You will get a combined file including all (correct) files indicated. If it's possible, sort the files before run the script because the files are imported in the indicated order.

Let me know if that suits you.

@+

1 reply

gregorym17975653
Known Participant
July 16, 2021

FYI,

Looks like I found sample code online in a PDF document entitled, "Developing Acrobat Applications Using Javascript" on page 47. I'm not sure what is wrong but it doesn't appear to be working successfully. Any assistance is greatly apprecaited. Below is a brief description of what I'd like to accomplish but it doesn't appear to be working successfully:

Combining PDF documents
You can customize and automate the process of combining PDF documents.
If you would like to combine multiple PDF files into a single PDF document, you can do so through a series
of calls to the Doc object’s insertPages method.
Example: Creating a new document from two other documents
// Create a new PDF document:
var newDoc = app.newDoc();
// Insert doc1.pdf:
newDoc.insertPages({
nPage: -1,
cPath: "/c/temp/doc1.pdf",
});
// Insert doc2.pdf:
newDoc.insertPages({
nPage: newDoc.numPages-1,
cPath: "/c/temp/doc2.pdf",
});
// Save the new document:
newDoc.saveAs({
cPath: "/c/temp/myNewDoc.pdf";
});
// Close the new document without notifying the user:
newDoc.closeDoc(true);

Legend
July 16, 2021

What console messages do you get? Please copy and paste them.

And how do you try to run the code (e.g. console, batch, mouse up event, privileged function...)?

bebarth
Community Expert
Community Expert
July 18, 2021

As indicated, it is not possible to read the content of a folder, but if all your files are in a same forder, you can copy then paste all the file names in a text field then use it to recover the names.

With macOS it very easy to do that, but I beleive it's a bit more complicated with a Windows OS.

I already did that, so let me know if you are interested with this solution and I'll send you an example file.

@+
P.S. Sorry, I didn't place my answer at the right place...