Merge pdf in one file linux

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

Читайте также:  Linux limit process number

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 Multiple PDF Files into One PDF in Linux

PDF or Portable Document Format files have more to offer to its users apart from the obvious advantages of being easily printable and shareable over a network.

Some other uniqueness of having a file converted or existing in PDF includes the following:

  • eSigning capabilities to give a file the needed authenticity.
  • Built-in security as a PDF file can be protected with passwords.
  • File encryption support.
  • Compact file size support.

Now that you know the advantages and importance of having your document files existing as PDF, there comes a time when you will have multiple inter-related PDF files existing separately.

You might also like:

At this point, collecting and moving these relatable PDF files into a single folder or directory might fix your file reference problem at the cost of efficiency.

You will have to switch between multiple open PDF files to get the bits of information you need from each file. An ideal solution, in this case, will be to merge all these relatable PDF files into a single PDF file.

Create PDF Files in Linux

Before we look at the techniques and approaches of merging multiple PDF files into a single PDF file, let us create three sample PDF files that we will attempt to merge. You can use LibreOffice to create three different word document texts and then export each of them to be saved as PDF files.

Export PDF in LibreOffice

In my case, I created three PDF files for this tutorial article:

Читайте также:  New linux kernel ubuntu

PDF Files in Linux

Ways to Merge Multiple PDF Files to a Single PDF File in Linux

We are going to look at two methods of merging multiple PDF files into a single PDF file in Linux. The First method considers merging a selection of PDF files into a single file. The second method considers merging all PDF files within a given folder or directory to a single file.

Method 1: Merging a Selection of PDF Files to a Single PDF File

Let us try to merge pdf1.pdf and pdf2.pdf files into a single file. To achieve this file merging objective, we are going to install and use the pdftk utility.

Reference the following pdftk installation commands in regards to your Linux operating system distribution. Make sure you are a Sudoer user or you have Sudo privileges on your Linux system.

$ sudo apt-get install pdftk [On Debian, Ubuntu and Mint] $ sudo yum install pdftk [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a sys-apps/pdftk [On Gentoo Linux] $ sudo pacman -S pdftk [On Arch Linux] $ sudo zypper install pdftk [On OpenSUSE]

To merge our two PDF files, we will reference the following command syntax:

$ pdftk pdf_file_1 pdf_file_2 cat output final_pdf_file

The above command syntax merges pdf_file_1 and pdf_file_2 to a newly created file called final_pdf_file.

Let us now merge our pdf1.pdf and pdf2.pdf files:

$ pdftk pdf1.pdf pdf2.pdf cat output pdf12.pdf

Merge PDF Files in Linux

Check for the existence of the merged file:

Check PDF Files in Linux

On opening the pdf12.pdf file, it showcases pdf1.pdf and pdf2.pdf files successfully merged in it.

View PDF Files in Linux

Method 2: Merging All PDF Files to a Single PDF File

In this section, we are going to attempt merging all PDF files inside the “LinuxShellTips PDF” folder without specifying their names.

List PDF Files in Linux

The command syntax to use is as follows:

$ pdftk *.pdf cat output final_pdf_file

In reference to the above command syntax, all files in the directory with a “.pdf” extension will be merged to a newly created PDF file called final_pdf_file.

Let us now merge our files:

$ pdftk *.pdf cat output pdf123.pdf

Merge PDF Files into One PDF

Check for the existence of the merged PDF file:

List Merged PDF Files in Linux

On opening the pdf123.pdf file:

View Merged PDF File in Linux

It accommodates all the three PDF files we created earlier.

Whether you want to merge multiple selections of PDF files or all PDF files existing in a single folder or directory, this article guide has shown you how to get the job done in a seamless manner. We hope this article lessens your file management routines.

Источник

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.

Читайте также:  How to run linux bash script

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:

  1. Open a new terminal window
  2. Use cd to enter the directory with the PDF files you want to merge
  3. Run: pdfunite file1.pdf file2.pdf output.pdf
  4. 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.

  1. Open PDF Arranger
  2. Drag and drop PDFs on to the window
  3. Click to arrange PDFs in to desired order
  4. Go to Menu > Save As…
  5. 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!

    Источник

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