Skip to main content
Tbadobe
New Participant
January 19, 2018
Answered

Merge by Name

  • January 19, 2018
  • 2 replies
  • 1097 views

hello all,

I have scoured the internet trying to figure out how to quickly merge files with the same unique identifier. I have 5000 files and there files are named As follows:

5772000001_1

5772000001_2

5772000001_3

5772000002_1

5772000002_2

1. Is there a way to combined the files by unique identifier? Combined file 1 would have the three files from above that have this prefix (5772000001) and the two files that have the prefix (57720000012)

2. Is there a way to saved the combined files to a folder that has that same prefix?

Any help would be greatly appreciated.

This topic has been closed for replies.
Correct answer Thom Parker

Yes, if you know the name and location of the files you can write a short script to loop through the names and insert the files into a merged file.

Something like:

var oMergeDoc = new Doc();

for(...files...)

     oMergeDoc.insertPages(oMergeDoc.numPages-1, <Path to File>);

2 replies

Tbadobe
TbadobeAuthor
New Participant
January 24, 2018

Thank you, Thom! I appreciate your help a great deal!

Thom Parker
Inspiring
January 19, 2018

This is a tricky one.  If you knew the file names and folder ahead of time you could do this with an automation script.

But a more general solution would be to use a script in an Action.  An Action script is run each time a new file is loaded into the Action. The script doesn't know if it's the first or the last file so the first thing it needs to do is look for an already open merge file, if this file does not exist it creates a new one page PDF. If the merge PDF does exist, then it inserts the new file into the merge PDF.  As well as creating the Merge PDF, the script would also need to collect information from the user about the target file names. And there is an ordering issue. The files are not loaded into the Action in any predicable order. So if ordering is needed, there has to be some way to sort the files for inserting.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Karl Heinz  Kremer
Braniac
January 19, 2018

Thom gave you an outline of how to do this within Acrobat. As you can see, it’s not straight forward. For cases like this, I prefer an approach that uses both Actobat to do the heavy PDF lifting and an application outside of Acrobat that handles the interaction with the user, reading of directories, and sorting filenames. You can e.g. program in VB or VBA (especially if you want to process information that comes from a spreadsheet) to do all file system operatione, and then use Acrobat’s IAC Interface to process the merging of PDF files.