Skip to main content
Participating Frequently
November 2, 2016
Question

How can I combine multiple files into single files with javascript?

  • November 2, 2016
  • 1 reply
  • 2589 views

I really hope I have this in the correct sub-forum.

I will try and make this short and sweet.

Any and all help is very very very much appreciated!

I have two folders with PDFs in them.

The first folder has the PDF files named: ABC_001, ABC_002, ABC_003, etc etc.

The second folder has the PDF files named: XYZ_001, XYZ_002, XYZ_003, etc etc.

I am running Adobe Acrobat 8 Professional. I do not have the opportunity to upgrade to a newer version of Adobe Pro so that is what I have to work with.

I need to combine the PDFs in the second folder with the PDFs in the first folder and save the resulting new PDF in a third folder. The new PDF also needs to maintain the naming scheme of the PDF from the first folder.

For example: XYZ_001 needs to be combined with and placed after ABC_001. The resulting new PDF should be saved in the third folder as ABC_001. If I were to open that new PDF, I would see the contents ABC_001 and then XYZ_001. Please note, it needs to be a single PDF, not a package.

So basically I need to merge/combine each ABC & XYZ PDF with the same ending 3 digit number into a new single PDF.

If I have 25 ABC PDFs (ABC_001 .... ABC_025) and 25 XYZ PDFs (XYZ_001 .... XYZ_025), I should have 25 PDFs at the end of it all, each PDF containing the ABC & XYZ with same ending 3 digits. I hope that makes sense.

I could use the combine button, but then I have to do each file individually. Sometimes I will have 3 files to generate, sometimes I Will have 500 files. Doing this manually with 50+ files is too time consuming. I would prefer to have it done automatically but am unsure on how to implement it. I am not strong at coding. If code is given to me, I can dissect it, understand it, and successfully manipulate it; but coming up with it on my own and having it work is an ongoing struggle for me.

Any ideas? Thank you again everyone for your assistance!

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
November 2, 2016

Are these folders located under the same parent folder? If not, do they both have fixed and known paths?

Doing it would involve using a combination of a batch sequence to collect the file-paths of the files in the folders (unless the file-paths are always the same) as well as a custom-made script to make the actual merge. It's not a very simple task, though.

Participating Frequently
November 2, 2016

The file paths to each folder is fixed and known.

I am already using batch sequence for a number of things with these same files.

I actually start out with several different word documents, spread sheets, and other PDFs. After doing mail merges, combing files, and splitting out files, all via javascript in batch sequence, I end up with the files ABC and XYZ. The last step is combing the same-numbered files of ABC and XYZ to make one single file. That is where I am stuck. I can't figure out how to do it wit javascript and/or any of the other functions.

I can work in batch sequence with javascript. It is just the actual coding that I am no good at. I understand how things work and if given to me, I can manipulate it. I am just not familiar with which calls to use and how they all function.

Complicated is fine.

try67
Community Expert
Community Expert
November 2, 2016

In your batch sequence you can use the insertPages command. Run it on the folder with the ABC files and then change the path of the file to insert to point to the other folder, and change the file name itself from ABC to XYZ.

So let's say the ABC files are under C:\ABC\ and the XYZ files are under C:\XYZ\. You can use this code in the batch that you run on the former:

this.insertPages({nPage: this.numPages-1, cPath: "/C/XYZ/" + this.documentFileName.replace(/ABC/, "XYZ")});

Then just set the output folder and you're done.