- Merge / convert multiple PDF files into one PDF [closed]
- 23 Answers 23
- How to Quickly Merge PDF Files on Linux
- Merging PDF Files on Linux
- 1. Using pdfunite (CLI)
- 2. Using PDF Arranger (GUI)
- Wrapping Up
- Joey Sneddon
- How to Merge PDF Files Using GUI & CLI Tools in Linux
- Merge Multiple PDF Files In Linux Using GUI App
- Install PDF Arranger On Linux
- Use PDF Arranger to Combine PDFs
- Merge Multiple PDF Files in Linux Command Line
- Install PDFtk On Linux
- Use PDFtk to Combine PDFs in Command Line
Merge / convert multiple PDF files into one PDF [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
How could I merge / convert multiple PDF files into one large PDF file? I tried the following, but the content of the target file was not as expected:
convert file1.pdf file2.pdf merged.pdf
I need a very simple/basic command line (CLI) solution. Best would be if I could pipe the output of the merge / convert straight into pdf2ps ( as originally attempted in my previously asked question here: Linux piping ( convert -> pdf2ps -> lp) ).
ymmv, but this doesn’t seem to have as good of a resolution in the output file as pdfunite and it also results in a file size larger than the output from pdfunite
Whenever links are preserved or not by those solutions is discussed in this post. If you want to preserve the links (probably along with other annotations), use pdftk if want a command-line interface, pdfsam if you want graphical user interface, sejda if you want a web interface.
The convert command line is from ImageMagick and it converts the PDF to an image before doing whatever else it will be doing.
23 Answers 23
Considering that pdfunite is part of poppler it has a higher chance to be installed, usage is also simpler than pdftk :
⚠ IMPORTANT: Just make sure you remember to provide out.pdf , or else it will overwrite the last input file in your command ⚠
pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf
A safer solution may include a test of non-existence
targeting the output file
export output_file=out.pdf && \ ! test -e $output_file && \ pdfunite in-1.pdf in-2.pdf in-n.pdf $output_file
Just make sure you remember to provide out.pdf, or else it will overwrite the last file in your command, sigh.
Cannot recommend this. The size of the the resulting PDF is far too big. For example: Pdfunite gives me a 75MB file while Ghostscript packs everything into 1MB.
You can use: pdfunite *.pdf out.pdf assuming no other pdf exists in that directory and their order is preserved by «*». If its not preserved, using ranges: filename_<0..9>.pdf solves it.0..9>
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf mine1.pdf mine2.pdf
or even this way for an improved version for low resolution PDFs (thanks to Adriano for pointing this out):
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=merged.pdf mine1.pdf mine2.pdf
In both cases the ouput resolution is much higher and better than this way using convert:
convert -density 300x300 -quality 100 mine1.pdf mine2.pdf merged.pdf
In this way you wouldn’t need to install anything else, just work with what you already have installed in your system (at least both come by default in my box).
UPDATE #1: first of all thanks for all your nice comments!! just a tip that may work for you guys, after googleing, I found a superb trick to shrink the size of PDFs, I reduced with it one PDF of 300 MB to just 15 MB with an acceptable resolution! and all of this with the good ghostscript, here it is:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf
UPDATE #2: In case you need to «burn» edits and compress a PDF made with Acrobat, this would help:
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=144 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile=compressed.pdf withedits.pdf
How to Quickly Merge PDF Files on Linux
In this guide I cover merging PDF files on Linux in two different ways: CLI and GUI.
If you’re comfortable at the command-line there’s a cool tool most Linux distributions come with that can do this task; or if you’re more comfortable clicking your way around there’s a user-friendly app for the task, available in most distro’s repos.
Either way, whether you’re a beginner or an experienced Linux user, by the end of this guide you’ll know how to merge PDF files quickly, easily, and all without affecting the quality of the content inside.
Merging PDF Files on Linux
1. Using pdfunite (CLI)
Combining multiple PDF files from the command-line is a cinch on Linux with open source tool pdfunite. Most Linux distributions have this available out-of-the-box (and on those that don’t, you can install the poppler-utils package to get).
To merge PDFs with pdfunite you just need to tell the tool which PDFs to merge into a single file, and give your combined PDF a file name:
- Open a new terminal window
- Use cd to enter the directory with the PDF files you want to merge
- Run: pdfunite file1.pdf file2.pdf output.pdf
- Hit enter to let the tool merge the PDF files
That’s it – you just successfully merged PDF files on Linux using pdfunite .
You can check everything merged correctly by opening the output.pdf file (or whatever file name you chose) in your preferred PDF app/document viewer.
2. Using PDF Arranger (GUI)
For a simple task like merging PDF files the (ably named) PDF Arranger app is ideal.
This Python-based app is available in the repos of most modern Linux distributions, though you’ll need to install it yourself (use your preferred method) first. Either search it out by name or drop to the command line and install, e.g., sudo def install pdf-arranger , etc.
- Open PDF Arranger
- Drag and drop PDFs on to the window
- Click to arrange PDFs in to desired order
- Go to Menu > Save As…
- Give merged file a name, location
Now, I will point out that this particular Python-based tool can do more than merely merge PDFs. You can use it to split multi-page PDFs in to individual ones, rotate PDFs, and (as you probably can guess from the name) rearrange pages inside of PDFs too.
Wrapping Up
In this post I focused on performing one task quickly. While there are a host of other PDF tools you can use to do the same job these are my go-to faves.
For expanded functionality, like editing PDF metadata, adding watermarks, or password protecting documents, you’ll want to look at more powerful apps. You can find plenty of free, (and not-so-free) ones by searching your distro’s repos or browsing sites like Flathub.
Home > How To > How to Quickly Merge PDF Files on Linux
Joey Sneddon
Joey Sneddon is a purveyor of puns and arbitrator of alliteration. Or at least, that’s what he says. When he’s not blogging about Ubuntu on omg! ubuntu! he’s collecting toys, feeding cats, and trying to master his Arch install…
- omg! linux! — covering the worlds of linux and open source
-
- About
- Privacy
- Commenting
- omg! ubuntu!
How to Merge PDF Files Using GUI & CLI Tools in Linux
Whether you prefer to use a command-line or graphical application, several tools are available for free to combine multiple PDF files in Linux.
In this article, I’ll help you to merge multiple PDF files into one PDF without breaking the PDF content. Considering the Linux experience level, I’ll use both free command-line and GUI-based applications.
Merge Multiple PDF Files In Linux Using GUI App
Using the graphical app is helpful for not just beginners who find it hard to remember or type commands in a terminal, but also to save time by doing things with a click of a button.
Now there are several Linux software available that combine PDF files into one PDF such as PDF Chain, PDF Arranger, PDFJumbler, and PDF Mix Tool.
Though you’re free to use any of the tools, I’ll use the PDF Arranger app that offers the following important features:
- Reorder PDF pages
- Merge multiple PDF documents
- Export all or selected page from a PDF
- Delete, rotate, and crop PDF pages
- Zoom in and out
- Edit PDF metadata
- Duplicate pages
- Page format
Install PDF Arranger On Linux
If you’ve already set up universal package manager Flatpak, you can install PDF Arranger using Flatpak by running a single command:
$ flatpak install flathub com.github.jeromerobert.pdfarranger
However, if you don’t have Flatpak, binary packages of PDF Arranger are also available for several Linux distributions. If none of the installation methods works, you can install it from the source code.
Use PDF Arranger to Combine PDFs
Once you install it successfully, open the app and click on the icon at the top left corner. It will pop up a dialog box, where you can select all PDFs you want to merge.
Now you can see a list of all pages from the selected PDFs. Here before you combine all pages, you can perform certain actions such as rearrange, delete, export, and edit metadata.
After doing the modification, click on the second or third icon at the top left corner to merge all pages in a single PDF file.
Merge Multiple PDF Files in Linux Command Line
Coming to the command line method of combining multiple PDF files, it can be helpful for system administrators who work on the server without a Linux desktop.
Similar to GUI apps, there are also several command-line tools available such as PDFtk, pdfconcat, Ghostscript, and pdfunite.
For this article I’ll use PDFtk, which comes in three variant:
- PDFtk Free: a free graphical app
- PDFtk Server: a free command-line tool
- PDFtk Pro: paid version with both CLI and GUI app
Being terminal-based does not mean that PDFtk Server lacks features. Like any other graphical PDF merger app, you can use PDFtk Server to perform the following functions:
- Merge PDF documents or collate PDF page scans.
- Split PDF pages into a new Document.
- Rotate PDF pages.
- Fill PDF Forms with X/FDF data and/or Flatten Forms.
- Add a background watermark or a foreground stamp.
- Edit PDF metadata.
- Attach files to PDF pages and unpack PDF attachments.
Install PDFtk On Linux
The easiest way to install PDFtk on Debian and Ubuntu-based Linux distributions is by running a single command:
$ sudo apt install pdftk-java
For CentOS, Fedora, and Red Hat, you first need to install libgcj dependency.
Then, you can download Binary RPM for Red Hat or CentOS – available for both 32-bit and 64-bit architecture.
If you cannot find a binary file for your Linux distro, you can also compile and build PDFtk Server from its source code.
Use PDFtk to Combine PDFs in Command Line
To join multiple PDFs, you need to give its name in the terminal along with the name of the single combined PDF.
$ pdftk pdf1.pdf pdf2 cat output out1.pdf
If you have got a large number of PDFs to combine, you can also use an asterisk (*) wildcards as *.pdf .
$ pdftk *.pdf cat output combined.pdf
PDFtk also allows encrypting and decrypting a PDF using the “owner_pw” and “input_pw” options.
$ pdftk unsecured-1.pdf output secured-1.pdf owner_pw xyz [Encrypt PDF file] $ pdftk secured-1.pdf input_pw xyz output unsecured.pdf [Decrypt PDF file]
To use other features of PDFtk like remove and delete pages from PDF, check out its official manual.
Based on your experience and situation, you can decide whether you want to use a command line or graphical tool to merge multiple PDF files into one PDF. PDF Arranger might seem easy to use on a Linux desktop, but PDFtk can be the choice on a server with no GUI.