开发者

How to batch Merger PDF documents

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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜