25

I have 250 pdf files in one folder that I want to merge in one document. The order does not matter. Is there a simple way of doing it?

I can use PDF-Shuffler as suggested here https://askubuntu.com/a/2805/247771 but the progam hangs for 10 minutes befor it has loaded all the pdfs.

Can I achive this maybe with an inline command like

pdftk *.pdf output mergedfiles.pdf

?

Adam
  • 2,300
  • 6
  • 33
  • 52

5 Answers5

41

I would use pdfunite. It is nice and simple. cd to your directory. Then use something like this:

pdfunite *.pdf all.pdf

(Before running, make sure you don't already have a file called all.pdf in that directory.)

jbrock
  • 3,227
  • 23
  • 33
  • 2
    Using `pdfunite version 0.68.0 ` with *Ubuntu 18.10*, I had to use `pdfunite * all.pdf`. When I tried `pdfunite *.pdf all.pdf`, it gave me the following error `I/O Error: Couldn't open file '*.pdf': No such file or directory. Syntax Error: Could not merge damaged documents ('*.pdf') `. – edesz May 05 '19 at 19:47
  • Works! Perfect!!! Thanks!! – ambigus9 Feb 15 '23 at 16:47
17

Thanks to steeldriver who showed me that this is doing the job:

pdftk *.pdf cat output mergedfiles.pdf
Adam
  • 2,300
  • 6
  • 33
  • 52
  • 1
    I have Kubuntu 19.10. this pdftk does not work. – rob grune Jan 25 '20 at 06:59
  • @robgrune pdftk in recent Ubuntu versions is a snap, which only works in your home folder, but fails silently elsewhere - like /tmp which is where I use it the most. Because the failure is silent (a particularly dumb misfeature of snaps) it's caught me out more than once, but a proper installation has worked on all (X|K)ubuntu versions for me for many years. Not also that you can't overwrite an output file in the same folder this way, but that error is clear – Chris H Jun 07 '23 at 14:27
11

You can use qpdf as pdftk is not available in Ubuntu Bionic:

qpdf --empty --pages *.pdf -- out.pdf
Zanna
  • 69,223
  • 56
  • 216
  • 327
SaTa
  • 946
  • 1
  • 15
  • 24
4
  1. sudo apt-get install gs
  2. gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=target.pdf -dBATCH xx.pdf xx.pdf xx.pdf ...
  3. you can get all filenames through ls -l *.pdf | awk command

Wish it helps . ^_^

tedyli
  • 43
  • 1
  • 5
1

You can use pdftools:

pdftools --input-dir dir_with_pdfs --output output.pdf
robertspierre
  • 1,012
  • 1
  • 8
  • 24