Linux joining pdf files

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.

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).

Читайте также:  Alt linux scx 3200

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 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, 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:

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

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

choose files to merge

Once you select files, click on the Merge button:

click on merge button

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

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.

Related read: List of PDF editors available for Linux.

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 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.

Читайте также:  Astra linux git lfs

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

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

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

save merged file from libreoffice

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 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

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:

Now, you have to change the rights=»none» to rights=read|write :

change policy in imagemagick to merge pdf files

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

merge pdf files using imagemagick in linux terminal

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.

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

Источник

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.

Читайте также:  Check configuration in linux

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.

Select PDF Files

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.

Merge PDF Files

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

Merge PDF Files in Linux Commandline

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.

Источник

Оцените статью
Adblock
detector