如何在 Linux 中合并 PDF 文件
PDF
![](/data/attachment/album/202304/17/155926wvvvh01v1vtcldd0.jpg)



> 
> 有多个关于同一主题的 PDF，现在你想将它们合并成一个 PDF？
> 
> 
> 


或者你可能需要上传由不同文件组成的单个文件？许多政府和学术门户网站都要求这样做。


作为 Linux 用户，如果你遇到需要合并 PDF 的情况，本教程将帮助你。


在本教程中，我将分享三种合并多个 PDF 文件的方法：


* 使用 PDF Tricks GUI 工具
* 使用 LibreOffice（允许你选择页面）
* 使用 ImageMagick 命令行工具（Linux 教程会没有终端方法就结束么？）


你可以全部了解一下并选择最适合你的。


### 方法 1：使用 PDF Tricks GUI 工具在 Linux 中合并 PDF


在试用了多种 GUI 工具后，我发现 PDF Tricks 使用简单且易于导航。


此外，除了合并 PDF 文件之外，它还包括其他功能，包括：


* 压缩 PDF。
* 拆分 PDF。
* 将 PDF 转换为 JPG、PNG 和文本格式。


它以 [Flatpak](https://itsfoss.com/what-is-flatpak/) 的形式提供。请 [确保你的 Linux 系统启用了 Flatpak 支持](https://itsfoss.com/flatpak-guide/)。


我分享的是在 Ubuntu 上启用 Flatpak 的步骤：



```
sudo apt install flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

```

现在，使用以下命令在你的系统中安装 PDF Tricks：



```
flatpak install flathub com.github.muriloventuroso.pdftricks

```

完成安装后，从系统菜单中打开 PDF Tricks 应用。


第一次运行时，你会得到一个可以使用此工具执行的操作列表。显然，要合并 PDF 文件，请使用第三个选项。


![merge pdf files using in ubuntu](/data/attachment/album/202304/17/155929bn9yzrvlgcvvgtcr.png)


在下一步中，单击 “<ruby> 添加文件 <rt>  Add file </rt></ruby>” 并选择要合并的文件：


![choose files to merge](/data/attachment/album/202304/17/155929f5vm7o7ka86q7pst.png)


选择文件后，单击 “<ruby> 合并 <rt>  Merge </rt></ruby>” 按钮：


![click on merge button](/data/attachment/album/202304/17/155929or2sjsjrjssuays2.png)


它将打开系统的默认文件管理器。你可以在此处选择要保存合并文件的位置以及应命名的文件：


![locate and name the merged pdf file](/data/attachment/album/202304/17/155930m9pdhwby87da6eg6.png)


就是这样。合并后的 PDF 已保存。


如果你正在寻找，我们提供了一份 [可用于阅读和编辑 PDF 文件的最佳 PDF 阅读器](https://itsfoss.com/pdf-editors-linux/) 列表。


### 方法 2：使用 LibreOffice 合并 PDF 文件


很棒的 LibreOffice 能够处理许多与 PDF 相关的任务。你甚至可以 [使用 LibreOffice Draw 工具编辑 PDF 文件](https://itsfoss.com/edit-pdf-files-ubuntu-linux/) 来添加数字签名、添加文本等。


好处是你不需要安装其他应用。LibreOffice 已经安装在大多数发行版上，如果不是全部的话。


打开文件管理器并选择要合并的 PDF 文件。


右键单击选定的文件 > <ruby> 使用其他应用打开 <rt>  Open With Other Application </rt></ruby> > LibreOffice Draw，它将打开选定的 PDF 文件。


它将在单独的 LibreOffice Draw 实例中打开你选择的每个 PDF 文件：


![open pdf file in libreoffice](/data/attachment/album/202304/17/155930xqbyad5bd57yajab.png)


现在，你必须从左侧预览栏选择单个页面或整个 PDF 文件（使用 `Ctrl + A`）并将其拖放到要合并的文件的预览栏：


拖放后，单击左上角的第 5 个选项，提示是 <ruby> 直接导出为 PDF <rt>  Export Directly as PDF </rt></ruby>：


![export directly as pdf in libreoffice](/data/attachment/album/202304/17/155930a6o6vwlwwslzw99g.png)


将打开一个文件管理器，你可以从中定位并命名文件：


![save merged file from libreoffice](/data/attachment/album/202304/17/155931gzn38ol378hpojil.png)


这就完成了！


### 更多技巧：在命令行中合并 PDF （对于高级用户）


如果我不包括命令行方法，那算什么 Linux 教程？要在命令行中合并 PDF 文件，你可以使用 ImageMagick。


ImageMagick 其实是一个图像相关的工具。PDF 文件本质上是图像，这就是 ImageMagick 可以处理它们的原因。


你可能甚至不需要单独 [安装 ImageMagick](https://itsfoss.com/install-imagemagick-ubuntu/)，因为它已经默认安装在大多数发行版中。


例如，我将添加 3 个名为 pdf-1.pdf、pdf-2.pdf 和 pdf-3.pdf 的 PDF 文件，并将最终合并的 PDF 文件输出命名为 MergedFile.pdf（多么聪明）：



```
convert pdf-1.pdf pdf-2.pdf pdf-3.pdf MergedFile.pdf

```

#### “no images defined” 故障排除


如果你看到这样的策略错误：


![](/data/attachment/album/202304/17/155931vgi4olatxppbwlgg.png)


这个问题很容易解决。你只需在 ImageMagick 策略文件中进行少量更改。


打开策略文件进行编辑：



```
sudo nano /etc/ImageMagick-6/policy.xml

```

并查找以下行：



```
<policy domain="coder" rights="none" pattern="PDF" />

```

现在，你需要将 `rights="none"` 更改为 `rights=read|write`：



```
<policy domain="coder" rights="read|write" pattern="PDF" />

```

![change policy in imagemagick to merge pdf files](/data/attachment/album/202304/17/155931scr1lg2qdq17cdhx.png)


保存更改，现在你可以使用 ImageMagick 轻松合并文件：


![merge pdf files using imagemagick in linux terminal](/data/attachment/album/202304/17/155932bynw533sxoz3kbx5.png)


### 总结


现在你知道了在 Linux 中合并 PDF 文件的几种方法。合并后的 PDF 文件可能很大。如果你需要在有大小限制的门户上传合并的 PDF 文件，你可以 [压缩 PDF 文件](https://itsfoss.com/compress-pdf-linux/)。


如果你在使用上述方法时遇到任何问题，请告诉我。


*（题图：MJ:process docs illustrations in high resolution）*




---


via: <https://itsfoss.com/merge-pdf-linux/>


作者：[Sagar Sharma](https://itsfoss.com/author/sagar/) 选题：[lkxed](https://github.com/lkxed) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

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, I’ll 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](https://itsfoss.com/what-is-flatpak/). Please [ensure that your Linux system has Flatpak support enabled](https://itsfoss.com/flatpak-guide/).

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](https://itsfoss.com/content/images/wordpress/2022/11/merge-pdf-files-using-in-ubuntu-1.png)

In the next step, click on **Add file** and select the files you want to merge:

![choose files to merge](https://itsfoss.com/content/images/wordpress/2022/11/choose-files-to-merge.png)

Once you select files, click on the **Merge** button:

![click on merge button](https://itsfoss.com/content/images/wordpress/2022/11/click-on-merge-button.png)

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](https://itsfoss.com/content/images/wordpress/2022/11/locate-and-name-the-merged-pdf-file.png)

And that’s 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.](https://itsfoss.com/pdf-editors-linux/)

[11 Best Linux PDF Editors You Can Use in 2023Looking for the best PDF editing options? You should find some awesome options here!](https://itsfoss.com/pdf-editors-linux/)![](https://itsfoss.com/content/images/wordpress/2017/09/Tools_TO_EDIT_PDF_IN_LINUX.png)


![](https://itsfoss.com/content/images/wordpress/2017/09/Tools_TO_EDIT_PDF_IN_LINUX.png)

## 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](https://itsfoss.com/edit-pdf-files-ubuntu-linux/) for adding a digital signature, adding text, and much more.

The good thing is that you don’t 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](https://itsfoss.com/content/images/wordpress/2022/11/open-pdf-file-in-libreoffice.png)

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:

![merge pdf in linux](https://itsfoss.com/content/images/wordpress/2022/11/merge-pdf-in-linux.gif)

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](https://itsfoss.com/content/images/wordpress/2022/11/export-directly-as-pdf-in-libreoffice.png)

And it will open a file manager from where you can locate and name the file:

![save merged file from libreoffice](https://itsfoss.com/content/images/wordpress/2022/11/save-merged-file-from-libreoffice.png)

And that’s it!

## Bonus Tip: Merge PDFs in the command line [For advanced users]

What kind of Linux tutorial would it be if I didn’t 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 don’t even need to [install ImageMagick](https://itsfoss.com/install-imagemagick-ubuntu/) 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.](https://itsfoss.com/content/images/wordpress/2022/11/convert-im6.q16-attempt-to-perform-an-operation-not-allowed-by-the-security-policy-pdf-@-error-constitute.c-iscoderauthorized-421.0a.png)

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](https://itsfoss.com/content/images/wordpress/2022/11/change-policy-in-imagemagick-to-merge-pdf-files.png)

Save the changes, and now you can easily merge files using ImageMagick:

![merge pdf files using imagemagick in linux terminal](https://itsfoss.com/content/images/wordpress/2022/11/merge-pdf-files-using-imagemagick-in-linux-terminal.png)

## 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](https://itsfoss.com/compress-pdf-linux/).

[How to Compress PDF in Linux [GUI & Terminal]Brief: Learn how to reduce the size of a PDF file in Linux. Both command line and GUI methods have been discussed. I was filling some application form and it asked to upload the necessary documents in PDF format. Not a big issue. I gathered all the scanned images and](https://itsfoss.com/compress-pdf-linux/)![](https://itsfoss.com/content/images/wordpress/2020/05/compress-pdf-linux.jpg)


![](https://itsfoss.com/content/images/wordpress/2020/05/compress-pdf-linux.jpg)

Similarly, you can use this neat little trick for simple PDF editing tasks such as [adding comments and highlighting texts in PDF](https://itsfoss.com/annotate-pdf-linux/).

[How to Add Comments to PDF in LinuxYou don’t need a dedicated PDF editor to add comments and highlight text. Here’s how you can use GNOME’s Document Viewer to annotate PDFs in Linux.](https://itsfoss.com/annotate-pdf-linux/)![](https://itsfoss.com/content/images/2023/08/annotate-pdfs-in-linux.png)


![](https://itsfoss.com/content/images/2023/08/annotate-pdfs-in-linux.png)

Let me know if you face any issues with above discussed methods.