How to merge several PDF files?

599,511

Solution 1

PDF Arranger (install), formerly known as PDF-Shuffler.

If you want a tool with a simple GUI, try pdfarranger. It allows for merging of PDFs as well as rearranging and deleting pages. For batch processing and/or more complicated tasks, pdftk is of course more powerful.

Screenshot of PDF-Shuffler

Solution 2

pdftk

To merge two pdf files, file1.pdf and file2.pdf:

pdftk file1.pdf file2.pdf cat output mergedfile.pdf

More info available hereWay Back Machine.

To install, run:

sudo snap install pdftk

Solution 3

Ghostscript is a package (available by default in Ubuntu) that enables you to view or print PostScript and PDF files to other formats, or to convert those files to other formats.
To use Ghostscript to combine PDF files, type something like the following:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf  file1.pdf file2.pdf

Here is a brief explanation of the command:

gs         starts the Ghostscript program.
-dBATCH    once Ghostscript processes the PDF files, it should exit.
           If you don't include this option, Ghostscript will just keep running.
-dNOPAUSE  forces Ghostscript to process each page without pausing for user interaction.
-q         stops Ghostscript from displaying messages while it works
-sDEVICE=pdfwrite 
           tells Ghostscript to use its built-in PDF writer to process the files.
-sOutputFile=finished.pdf
           tells Ghostscript to save the combined PDF file with the specified name.
-dAutoRotatePages=/None
           Acrobat Distiller parameter AutoRotatePages controls the automatic orientation selection algorithm: For instance: -dAutoRotatePages=/None or /All or /PageByPage.

Your input files don't even need to be PDF files. You can also use PostScript or EPS files, or any mixture of the three.

There is a lot you can do with Ghostscript. You can read its documentation for more details.

Source

Solution 4

You also also use pdfunite to merge pdf documents :

pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf

To install pdfunite if it is not installed already, run:

sudo apt-get install poppler-utils

Solution 5

PDF Chain Install PDF Chain

A very nice solution is PDFChain. It's GUI is a frontend of PDFTK where you can merge, split or even add some background to your PDF files.

Share:
599,511

Related videos on Youtube

Deependra Solanky
Author by

Deependra Solanky

I am from India, working on Microsoft Technologies like ASP.NET, SQL Server. I like to read new things about technology on internet on daily basis via Google Reader. I like open source and as a result have some knowledge of PHP/Ruby on Rails/Python. If Microsoft had not introduced ASP.NET MVC one year back, there were chances of me jumping into non-microsoft camp.

Updated on September 17, 2022

Comments

  • Deependra Solanky
    Deependra Solanky over 1 year

    There are a lot of software in Windows to merge PDF files but how can we do the same in Ubuntu?

    • Grijesh Chauhan
      Grijesh Chauhan almost 10 years
      I found this link
  • vishal
    vishal about 12 years
    I tried this - it didn't work on 10.04
  • aidan
    aidan about 11 years
    True, but it's incredibly slow. I just tried concatenating 45 x 400K, single-page PDFs. pdftk took 0m0.484s, gs took 1m32.898s (that's almost 200x slower) The file from gs was about 21% smaller though.
  • Pushpak Dagade
    Pushpak Dagade about 11 years
    pdftk is buggy - bugs.launchpad.net/ubuntu/+source/pdftk/+bug/779908. gs might be slow, but does the work perfectly [IgnitE's answer]
  • Swastika  Srivastava
    Swastika Srivastava about 11 years
    On 12.04, pdfshuffler always complains that there are "too many values to unpack", making it unusable.
  • user1251007
    user1251007 over 10 years
    For me it works under 12.04 64-bit, pdfshuffler version 0.6.0
  • Zlatty
    Zlatty over 10 years
    Installs and works like a charm on 14.04. Thanks a bunch!!
  • Antonios Hadjigeorgalis
    Antonios Hadjigeorgalis about 10 years
    this command also works if you use a wildcard for the list of files to be combined. for example, replace file1.pdf file2.pdf with file*.pdf
  • krlmlr
    krlmlr over 9 years
    WARNING: An existing file out.pdf will be overwritten without warning, so pdfunite *.pdf won't work as expected.
  • BЈовић
    BЈовић over 9 years
    @krlmlr You can always put the output into another directory.
  • ntc2
    ntc2 over 9 years
    For me gs worked with some "non conformant" PDFs where pdftk would just run forever.
  • csgeek
    csgeek over 9 years
    I used to use pdftk for this behavior. Thanks for the PDF Shuffle reference. It looks really slick.
  • tripleee
    tripleee about 9 years
    The process substitution is superfluous and potentially even harmful. A correct an much simpler command line is pdfunite output_*.pdf out$(date +%Y-%m-%d-%H_%M_%S).pdf but it lacks the ordering of ls -v. An obvious and trivial fix is to name your files so that they naturally sort in the order you want to include them. If you absolutely want ls -v, you can at least lose the pipe to tr, which accomplishes nothing here.
  • tripleee
    tripleee about 9 years
    Upvote: This is a simple command-line tool without a click-and-drool GUI like many of the other answers here. It nicely encapsulates the complexities of the (largely equivalent) GhostScript solution.
  • rsmoorthy
    rsmoorthy almost 9 years
    This is also very fast. Does the job well. On a very slow server (aws t1.micro), gs takes 9 secs, pdftk takes 4 secs and this pdfunite takes 0.9 secs for merging two files!
  • The Unknown Dev
    The Unknown Dev about 8 years
    This is the quickest and easiest solution. Thank you! (Ubuntu 14.04 64-bit)
  • Dave
    Dave about 8 years
    This works well in many cases but I noticed that it stripped out hyperlinks. Using pdftk does not strip out hyperlinks. So, if there is any complexity to the PDFs that you are concatenating, I would use the command line tool; at the very least, thoroughly test your output file.
  • Mohnish
    Mohnish about 8 years
    Use -dPDFSETTINGS=/prepress option from quality improvement. All thanks due to the original contributor
  • Jonathan Komar
    Jonathan Komar about 8 years
    @PushpakDagade ghostscript messes up with annotations, particularly comments that have been checked (check box ticked with checkmark), will no longer have this checkmark. I am not aware of a way around this. Also, if you merge PDF v1.5 + 1.6, output will be 1.4 by default. That is strange behavior.
  • Midgard
    Midgard almost 8 years
    @AntoniosHadjigeorgalis Just for reference and good understanding: that's not the command supporting wildcards, that's actually the shell replacing file*.pdf with file1.pdf file2.pdf before passing the arguments to the command.
  • user643722
    user643722 almost 8 years
    This is also available under Cygwin.
  • Fidel Pérez Menéndez
    Fidel Pérez Menéndez almost 8 years
    I merged ~20 small pdfs into a single file in a fraction of a femto-second with gs. No need to download 70MB of pdftk. Thanks @ignite!
  • Sir_FZ
    Sir_FZ over 7 years
    +1 Worked with encrypted pdfs as well (these annoying files that can be viewed but not merged without a password).
  • Paolo Mioni
    Paolo Mioni over 7 years
    This worked fine for me on Ubuntu 16.04 with no extra downloads. Merging 4 pages was almost instantaneous.
  • Sanjay Manohar
    Sanjay Manohar over 7 years
    Also works great on 16.04.1
  • vaquito
    vaquito over 7 years
    @aidan sounds like gs rerenders the files instead of just copying the content. This might be a good thing if you want a distiller like workflow
  • Paulo Coghi
    Paulo Coghi over 7 years
    This is the best answer. It works perfectly, regardless of the Ubuntu version.
  • my account_ram
    my account_ram about 7 years
    Worked on Ubuntu 14.04 without hassle!
  • Volomike
    Volomike almost 7 years
    To get this on Ubuntu 16.04, run sudo apt-get install poppler-utils. You'll then be able to type pdfunite --help and see that it's installed.
  • Geppettvs D'Constanzo
    Geppettvs D'Constanzo over 6 years
    This is beautiful. Working pretty fine on 14.04.5 LTS and we can merge PDF's with different page size/orientation. Produces high quality and low size files. Thank you!
  • COil
    COil over 6 years
    Gave it a try and works well on 17.04. Very easy to use for basic merge.
  • Jeff Puckett
    Jeff Puckett over 6 years
    pdftk has an unusual usage where commands cat and output follow variadic input arguments and followed again by an output argument.
  • orschiro
    orschiro over 6 years
    Works great on Ubuntu 18.04!
  • Ruthvik Vaila
    Ruthvik Vaila about 6 years
    This doesn't work for combining encrypted transcripts.
  • Nicolas Raoul
    Nicolas Raoul about 6 years
    The package seems to have been removed in 2018.04.
  • user2413
    user2413 almost 6 years
  • user2413
    user2413 almost 6 years
    does not do merging.
  • Max
    Max almost 6 years
    @NicolasRaoul I just downloaded it as a snap install.
  • Nicolas Raoul
    Nicolas Raoul over 5 years
    @Max do you know what is the difference between the two snaps at snapcraft.io/search?category=&q=pdftk ?
  • GrayedFox
    GrayedFox over 5 years
    FYI: sudo snap install pdftk - there is no release candidate for the aptitude app anymore, it was deprecated by the author, who created the snap package.
  • jena
    jena over 5 years
    it did merging in the past, now it's just crashing, I used the pdfshuffler instead and it worked great
  • HD189733b
    HD189733b over 5 years
    The gs method will break the href and url link in the pdf created by pdflatex. pdfshuffler can keep the link.
  • Tzunghsing David Wong
    Tzunghsing David Wong over 5 years
    Tried PdfShuffler 0.6.0 (apt-get install pdfshuffler) on Ubuntu 14.0 64-bit and it works with one caveat - It has problem dealing with some special characters in the filename (in my case pdfshuffler cannot load filename with #)
  • jena
    jena over 4 years
    @user2413 that's a snap store, not the only source for software in Ubuntu. Trying to search in apt didn't give any results either though :/
  • cipricus
    cipricus over 4 years
    @GrayedFox in 18.04
  • cipricus
    cipricus over 4 years
    @NicolasRaoul in 18.04
  • Bas Swinckels
    Bas Swinckels over 4 years
    Version 0.6.0 works like a charm on 18.04
  • Flimm
    Flimm over 4 years
    How is this installed in newer Ubuntu versions?
  • Flimm
    Flimm over 4 years
    It would be better if these were separate answers so that they could be upvoted separately and edited separately.
  • Flimm
    Flimm over 4 years
    pdftk is mentioned in this answer: askubuntu.com/a/2802/2355
  • Flimm
    Flimm over 4 years
    @NicolasRaoul On the website, pdftk-smoser is marked as obsolete.
  • Topera
    Topera over 4 years
    Works greatly on 18.04
  • Nir
    Nir over 4 years
    A handy shortcut: pdftk file* cat output mergedfile.pdf
  • Will59
    Will59 about 4 years
    Just used it on 19.10, to merge and crop a series of pdf, worked like a charm.
  • Will59
    Will59 about 4 years
    Used it under 19.10 to merge file: simple interface, a few options, works very well. But other features such as crop are premium options. sudo apt-get install pdfshuffler did the trick :-)
  • zugzug
    zugzug about 4 years
    Nice tool. Works like a charm on my Ubuntu 18.04 LTS
  • michael
    michael almost 4 years
    It works great. To install on Ubuntu 20.04 LTS do: sudo apt install pdftk-java
  • Carl Zulauf
    Carl Zulauf almost 4 years
    This tool has been renamed to pdfarranger as of Ubuntu 20.04. You can still install pdfshuffler via apt, but it is just an empty pointer to pdfarranger which is also the command you'll need after install.
  • Timo
    Timo almost 4 years
    jdk is an overkill and should not be necessary.
  • Billal Begueradj
    Billal Begueradj over 3 years
    This is the best approach because the result will always be there, no bugs
  • desmond13
    desmond13 over 3 years
    I have the following error: Error: Failed to open PDF file: ...
  • Gireesh
    Gireesh about 3 years
    This is crashing in ubuntu 16.04. I have tried pdftk which is not gui based application
  • MWB
    MWB about 3 years
    I'm using this to concatenate 3 files, and gs inexplicably takes the title of one of them and uses it as the title of the new document (shown in the title bar by the PDF viewer). I wonder if the new title could be specified explicitly.
  • Timo
    Timo about 3 years
    This works:gs -dBATCH -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf, no need for the -q and -dnopause which did not help to output more silent. No need for dAutoRotatePages.
  • Timo
    Timo about 3 years
    cat is not needed I think.
  • Celal Ergün
    Celal Ergün about 3 years
    sudo snap install pdftk can be used in Ubuntu 20.04 and pdftk is accepting "*.pdf" as a valid parameter.
  • Frank Nocke
    Frank Nocke almost 3 years
    Interesting: pdfunite is available by default in Ubuntu MATE 20.04. (I certainly didn't install it...)
  • qwr
    qwr almost 3 years
    askubuntu.com/questions/1028522/… it exists as pdftk-java and can be used as pdftk
  • user140259
    user140259 over 2 years
    The sheets were returned with different sizes.
  • Giovanni Bassi
    Giovanni Bassi over 2 years
    Worked really well, I used gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf * (with the wildcard). Great, and open source. Thanks!
  • topher217
    topher217 about 2 years
    @CarlZulauf can you provide a link to documentation showing this renaming of pdfarranger? I'm not seeing any evidence of this in apt and not able to get pdfshuffler to work at that.
  • Carl Zulauf
    Carl Zulauf about 2 years
    @topher217 APT will tell you pdfshuffler is just pdfarranger. On Ubuntu 20.04 try $ apt show pdfshuffler and look closely.
  • topher217
    topher217 about 2 years
    @CarlZulauf maybe you or I have a manually added an apt repo to pdfshuffler? I'm not seeing anything. Here is the pastebin of the output from apt show pdfshuffler. This is after running sudo apt update just in case. I'm on Ubuntu 20.04 with apt -v returning apt 1.6.14 (amd64). The only docs on pdfarranger I found were the github repo which doesn't appear to give any apt based instructions for installation but rather via pip.
  • Admin
    Admin almost 2 years
    pdftk does not work if there spaces in the filenames