9

I have 3 folders:

Folder 1 
Folder 2
Folder 3

In each folder I have 5 pdf files:

    Folder 1 
       file1.pdf
       file2.pdf
    Folder 2
       file1.pdf
       file2.pdf
    Folder 3
       file1.pdf
       file2.pdf

I want that in each folder to have a combined file of those two files:

    Folder 1 
       binder.pdf
    Folder 2
       binder.pdf
    Folder 3
       binder.pdf

Any idea? Don't tell to do it manually. This case is just to explain you my problem. Think that I have hundreds of folders. :) Maybe I can use another tool instead of Adobe Acrobat?!

  • What exactly do you mean by "have a combined file of those two files"? Would concatenate and merge these two files into 1 PDF work for you? – Kurt Pfeifle Feb 23 '12 at 23:03
  • Adobe Acrobat or Adobe Acrobat Reader? – wmz Aug 24 '12 at 23:13
  • @AndreiAndre Many good solutions were posted to your question. Maybe you could choose the one which fits all your needs and mark it as accepted. – nixda Feb 11 '13 at 9:35
12

You can do this with a short batch file and pdftk.exe (not pdftk Builder which is the GUI version).
There is no need to install anything.

Preparation

  • download & extract pdftk with UniExtract
  • Open ..\pdftk\bin* and copy pdftk.exe and libiconv2.dll to a folder of your choice
  • create a new text file and paste the following code

    @echo off
    setlocal enabledelayedexpansion
    FOR %%A IN (%*) DO (set command=!command! %%A)
    pdftk.exe %command% cat output "%~dp1binder.pdf"
    
  • Save it as merge@pdf.cmd in the same folder as pdftk.exe and libiconv2.dll enter image description here
  • create a shortcut of this .cmd and place it in your sendto folder (Win+R » shell:sendto)

Usage

  • Go to a folder with some PDF files and select as many PDFs as you want
  • Right-click them and choose the shortcut you just created
  • a new binder PDF in the same folder will be created where all selected PDFs are merged into one

    enter image description here

Update: Version which uses current folder name as file name for generated pdf

@echo off
setlocal enabledelayedexpansion
:: Concat all paths fromselected files and save it as command
FOR %%A IN (%*) DO (set command=!command! %%A)

:: Take path from first selected file and save it as path
set path=%~dp1
echo %path%

:: Check if a trailing slash is present. If yes, remove it
IF %path:~-1%==\ SET path=%path:~0,-1%

:: Get last folder from path
FOR %%F in ("%path%") do (set lastFolder=%%~nxF)

:: Call pdftk, pass on command. use lastFolder as filename
pdftk.exe %command% cat output "%path%\%lastFolder%.pdf"
  • VERY nice answer. I am struggling to modify it, so it saves as the FOLDERNAME instead of binder.pdf. How could I do that? – Chen Stats Yu Aug 22 '18 at 23:29
  • @ChenStatsYu See update – nixda Aug 23 '18 at 10:50
  • GREAT!! Sorry to ask again, not sure if I should start a new post. Just one last request, as I am repeating this for nearly 40/50 folders, can we modify it to send the "folder" to the cmd and use the foldername, instead of selecting some pdfs from the folder? – Chen Stats Yu Aug 23 '18 at 22:33
  • Also, I am hoping to have it supporting non-English foldernames. – Chen Stats Yu Aug 23 '18 at 22:47
5

If you're on Linux (or Mac, or any environment where it is installed), you can use a command-line tool called ghostscript to combine them.

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH file1.pdf file2.pdf file3.pdf

You can also use the following to combine all files in the current folder

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH *.pdf 

You can download ghostscript here. There's a Windows version as well, but I didn't test it.

  • 1
    It works on windows, too. I had to write the full path to the ghostscript executable (on my PC it's "c:\Program File\gs\gs9.07\bin\gswin32c.exe") and the "*.pdf" expansion doesn't work, but ghostscript itself works perfectly. – Pitarou Feb 22 '13 at 7:05
3

I have used the above solution successfully. However, on my system (Windows 7 64-bit) the code as it is adds the PDFs in (apparently) random order, not alphabetically by filename.

To get it to add files in alphabetic order you will need to add the sort-object parameter to the DIR (aka Get-ChildItem) command (the sort-object takes no parameter here as filename/alphabetically is the default):

dir $inputfolder -r -include *.pdf -exclude $outputfile | sort-object | group DirectoryName % {& $PDFtk $.group CAT OUTPUT "$($.Name)\$outputfile" verbose}

Those who have filenames of the form 1.pdf 2.pdf ... 10.pdf etc. rather than 01.pdf 02.pdf .. 10.pdf may also like to try a variation of this:

pdftk *?.pdf *??.pdf *???.pdf *????.pdf cat output out.pdf
  • "above solution" - presumably you mean nixda's solution. If your answer got voted higher than nixda's it would be below – noodle Jan 28 '18 at 9:32
1

There is a new online Advanced PDF Manipulation tool called Sej-da which is still in Beta, which has a myriad of PDF functions (inc ability to merge multiple pdfs). It free & could well help your needs.

http://sejda.com/

A brief review of its functions was carried out only a couple of weeks ago by Revision 3:

http://revision3.com/tzdaily/sejda-online-pdf

  • the OP is clearly capable of merging pdf files, he wants to batch merge with an automated process. Your answer gives no details as to how to use sejda in this way, neither is it apparent from their website – noodle Jan 28 '18 at 9:27
1

Perhaps it is better to use a batch scenario. Create and collect all your pdf files as xxxx.abcdef.pdf.

First part is the so-called batch tag; second part is file identifier (file name). Tags for each back are similar in length and value; name of files come after the point.

For instance your first batch consists of 1111.3425.pdf, 1111.76501.pdf, so on. Your second batch is 22222.1432.pdf, 22222.4398, so on. And so on and so forth for other batches.

Then you can use automated merge software that can deal with thousands of files creating a separate merge for each batch. I found this Dysprosium free software that does not need a command line or a batch script. You can download it as a portable JAR file. It has different automated scenarios; one described in this answer as tagging and one as your required folder separated.

Depending on your hardware you can batch merge thousands of files into pre-destined batches.

0

Try PDFMerge. But don't use the initial form where you have to select each file one by one. Instead, wait for the site to check your Java installation, then click on "Try the PDFMerge Java Applet" link. Once the applet is loaded and allowed to run, click on Choose files button, and you'll be able to select multiple files (to merge into one file).

The merging will be superfast and will be able to handle large number of files as nothing is uploaded into the website. Everything is done in your computer itself using your Java installation.

PS: Sorry if you're looking for an offline software that can be customized to create single PDF files across multiple folders.

0

If you are on mac you could create an Automator script to achieve this task. Make it as a folder action and simply drop the pdfs into it and see it happen! If you want I can show you how, are you running mac?

0

On Linux

I wrote this rather long command line

tree -fai . | grep -P ".pdf$" | xargs -L1 -I {} dirname {} | uniq | xargs -L1 -I {} bash -c 'cd "$0" && pdftk *.pdf cat output binder.pdf' {}

But it does the job, I tested it, it also works with how many levels of folders you have. Just make sure that you run it a the root of the folder structure.

You need pdftk and tree for this and on Ubuntu Linux you can install it with apt:

sudo apt install pdftk tree

protected by Community Oct 25 '14 at 16:08

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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