TranslateProject/sources/tech/20221124.1 ⭐️ How to Merge PDF Files in Linux.md

183 lines
7.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[#]: subject: "How to Merge PDF Files in Linux"
[#]: via: "https://itsfoss.com/merge-pdf-linux/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to Merge PDF Files in Linux
======
Got several PDFs on the same subject and now you want to combine them into a single PDF?
Or perhaps you need to upload a single file consisting of different files? Many government and academic portals require that.
As a Linux user, if you are in a situation where you need to merge PDFs, this tutorial will help you out.
In this tutorial, Ill share three methods of combining multiple PDF files:
- Using PDF Tricks GUI tool
- Using LibreOffice (allows you to select pages as well)
- Using the ImageMagick command line tool (Can a Linux tutorial be completed without the terminal method?)
You can read them all and pick the one that works best for you.
### Method 1: Use PDF Tricks GUI tool to merge PDF in Linux
After experimenting with several GUI tools, I found that the PDF Tricks was straightforward to use and easy to navigate.
Furthermore, it includes additional functionality beyond only merging PDF files, including:
- Compress PDFs.
- Split PDFs.
- Compress PDFs (into JPG, PNG, and text formats).
It is available as a [Flatpak][1]. Please [ensure that your Linux system has Flatpak support enabled][2].
I am sharing the steps for enabling Flatpak on Ubuntu:
```
sudo apt install flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
```
Now, use the below command to install PDF Tricks in your system:
```
flatpak install flathub com.github.muriloventuroso.pdftricks
```
Once you are done with the installation, open the PDF Tricks application from the system menu.
On the first run, you will get you a list of actions you can perform with this tool. To merge PDF files, go with the third option, obviously.
![merge pdf files using in ubuntu][3]
In the next step, click on **Add file** and select the files you want to merge:
![choose files to merge][4]
Once you select files, click on the **Merge** button:
![click on merge button][5]
And it will open the default file manager of your system. Here you can select where you want to save the merged file and what it should be named:
![locate and name the merged pdf file][6]
And thats it. The combined pdf has been saved.
And if you are looking for a tool, we have a list of the [best PDF readers that you can use to read and edit PDF files.][7]
**Related read**: List of [PDF editors available for Linux][7].
### Method 2: Merge PDF Files using LibreOffice
The awesome LibreOffice is capable of handling many PDF related tasks. You can even [edit PDF files with LibreOffice Draw tool][8] for adding a digital signature, adding text, and much more.
The good thing is that you dont need to install another application. LibreOffice is already installed on most distributions, if not all.
Open the file manager and select the PDF files that you want to merge.
**Right-click on selected files > Open With Other Application > LibreOffice Draw from there**, and it will open selected PDF files.
And it will open every PDF file you selected in a separate LibreOffice Draw instance:
![open pdf file in libreoffice][9]
Now, you have to **select individual pages or entire PDF file** (using Ctrl + A) from the left preview bar and drop it to the preview bar of the file that you want to combine with:
Once you are done with drag and drop, click on the 5th option from the top left, labeled as **Export Directly as PDF**:
![export directly as pdf in libreoffice][10]
And it will open a file manager from where you can locate and name the file:
![save merged file from libreoffice][11]
And thats it!
### Bonus Tip: Merge PDFs in the command line [For advanced users]
What kind of Linux tutorial would it be if I didnt include the command line method? To merge PDF files in the command line, you can use ImageMagick.
ImageMagick is actually an image-related tool. PDF files are essentially images and this is why ImageMagick can work with them.
You probably dont even need to [install ImageMagick][12] as it is already installed in most distros by default.
For example, I will be adding 3 PDF files named pdf-1.pdf, pdf-2.pdf, and pdf-3.pdf and will name the final merged PDF file output as MergedFile.pdf (how clever):
```
convert pdf-1.pdf pdf-2.pdf pdf-3.pdf MergedFile.pdf
```
#### Troubleshooting no images defined
If you see a policy error like this:
![convert im6.q16: attempt to perform an operation not allowed by the security policy `pdf' @ error constitute.c iscoderauthorized 421.][13]
The problem is quite easy to solve. You just have to make minor changes in the ImageMagick policy file.
Open the policy file for editing:
```
sudo nano /etc/ImageMagick-6/policy.xml
```
And look for the following line:
```
<policy domain="coder" rights="none" pattern="PDF" />
```
Now, you have to change the `rights="none"` to `rights=read|write`:
```
<policy domain="coder" rights="read|write" pattern="PDF" />
```
![change policy in imagemagick to merge pdf files][14]
Save the changes, and now you can easily merge files using ImageMagick:
![merge pdf files using imagemagick in linux terminal][15]
### Wrapping Up
Now you know several ways of combining PDF files in Linux. Chances are that the merged PDF file is big in size. If you have to upload the merged PDF file on a portal that has size restrictions, you can [compress the PDF file][16].
Let me know if you face any issues with above discussed methods.
--------------------------------------------------------------------------------
via: https://itsfoss.com/merge-pdf-linux/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed
[1]: https://itsfoss.com/what-is-flatpak/
[2]: https://itsfoss.com/flatpak-guide/
[3]: https://itsfoss.com/wp-content/uploads/2022/11/merge-pdf-files-using-in-ubuntu-1.png
[4]: https://itsfoss.com/wp-content/uploads/2022/11/choose-files-to-merge.png
[5]: https://itsfoss.com/wp-content/uploads/2022/11/click-on-merge-button.png
[6]: https://itsfoss.com/wp-content/uploads/2022/11/locate-and-name-the-merged-pdf-file.png
[7]: https://itsfoss.com/pdf-editors-linux/
[8]: https://itsfoss.com/edit-pdf-files-ubuntu-linux/
[9]: https://itsfoss.com/wp-content/uploads/2022/11/open-pdf-file-in-libreoffice.png
[10]: https://itsfoss.com/wp-content/uploads/2022/11/export-directly-as-pdf-in-libreoffice.png
[11]: https://itsfoss.com/wp-content/uploads/2022/11/save-merged-file-from-libreoffice.png
[12]: https://itsfoss.com/install-imagemagick-ubuntu/
[13]: https://itsfoss.com/wp-content/uploads/2022/11/convert-im6.q16-attempt-to-perform-an-operation-not-allowed-by-the-security-policy-pdf-@-error-constitute.c-iscoderauthorized-421.0a.png
[14]: https://itsfoss.com/wp-content/uploads/2022/11/change-policy-in-imagemagick-to-merge-pdf-files.png
[15]: https://itsfoss.com/wp-content/uploads/2022/11/merge-pdf-files-using-imagemagick-in-linux-terminal.png
[16]: https://itsfoss.com/compress-pdf-linux/