0

I am looking for either a batch file or a vbscript that will merge like pdf file names. The files that should be combine will have the same file name all the way to the first "." I have entire folders that contain about 4000 files. The file extensions match the following format

1111111111111111.22222222.pdf ==> 1 is any 16 numbers 0-9 and 2 is any 8 numbers 0-9

I would like to merge the like files of the folder in batch style. All the files that have identical file name up to the first should be merged "."

Example: 1111111111111111.25484686.pdf should merge with 1111111111111111.54874568 while 5555555555555555.78468767 should merge with 5555555555555555.48687654 and 5555555555555555.68974582

The files could be outputted to another folder but is not required. The new file name after it is outputted doesnt matter either as long as it works.

I know that there is software that is out there that will handle this but it would take too long to drag and drop all like files to merge them.

3
  • 1
    Batch files\VBscript have no inherent ability to merge PDF files. So first you'll need to find some software that can do that, and which also have an API that's usable from VBS or a batch file. I'd suggest that you might be able to ask for this on Superuser. When you've found that, you can then ask for help here on SO in how to write the script to automate the processing. Aug 19, 2011 at 7:38
  • I agree with @ho1. I don't want to close your question, but it would be better if you follow the advice and find software specific to your purpose then come back and edit this question for the scripting. Aug 19, 2011 at 12:37
  • I was hoping that this would not be the case. I have tried about everything and everyone has said the same thing. this is unfortunate because I know that this would be effective for many companies. Thanks anyways.
    – CLO_471
    Aug 22, 2011 at 14:55

2 Answers 2

3

A Google search found http://www.pdfsam.org/ - a site that offers a free PDF merge utility that has a command line interface (as well as a GUI). I have no idea how well this works. Make sure you get the free utility offered by this site and not the competitor's solution that is advertised on the same site.

There are many other utilities out there, most of them for a fee.

Once you figure out how to use the command line interface of your utility of choice, you can use a batch file like the one below to dynamically build your list of files to merge. (This batch code is untested. The concept will definitely work, but it may need some debugging)

@echo off
setlocal enableDelayedExpansion

:: This initial loop determines which files need to be merged
:: and then calls :merge for each unique set of files. This top
:: loop should work no matter what utility you choose.
set "current="
set cnt=0
:: for current directory, LOC should be empty (or .\)
:: for any other path, LOC should include \ at end
set "LOC="
for %%F in ("%LOC%*.*.pdf") do (
  for /f "tokens=1,* delims=." %%A in ("%%~nF") do (
    if "%%A" neq "!current!" (
      if defined current call :merge
      set cnt=0
      set current=%%A
    )
    set /a cnt+=1
    set pdf.!cnt!=%%~fF
  )
exit /b


:merge
:: This routine should build the command line to merge the current
:: file list contained in pdf.1 through pdf.!cnt!
::
:: Below is code to build a hypothetical file list to be used on
:: the merge command line. This will obviously need to be modified
:: based on the syntax of your chosen merge utility.
::
  set "list="
  for /l %%N in (1 1 !cnt!) do set list=!list! -f "!pdf.%%N!"
::
::
:: The rest is up to you!
::
exit /b
0

This software, Dysprosium, can batch-merge without writing a batch file being necessary and without drag and drop and it is free to get and use. It is enough to put all the batch in the same folder, as expected. But you need to have hardware resources proportional to the size of files in your batch.

It is a simple light "JAR" file portable without being installed on operating system.

As it is a Java based software, you also need to increase the Java memory available for Java run time. Java needs to grab a portion of physical memory to render large PDF files. This wiki explains how you can increase Java Run Time Memory.

(IMHO) With off the shelf software you can't merge PDF batches which are in total size greater than 3GB-3.5GB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.