Linux pdf merge pdf files

HowTo: Merge PDF Files – Linux Command Line

Sometimes it is required to merge several PDF files into a one PDF file.

In Linux we can easily join multiple PDF files using the command line utility called convert that is a part of ImageMagick software suite.

From this article you will learn how to merge entire PDF files into one PDF file or how to join specific PDF pages only into a single PDF file.

Cool Tip: Merge PDF files in Linux using the ghostscript command! Read more →

First of all it is required to install the ImageMagick suite that provides the convert utility:

$ sudo apt-get install imagemagick

Convert Multiple PDF Files Into One

Merge two PDF files FILE1.pdf and FILE2.pdf into the new OUTPUT.pdf file:

$ convert FILE1.pdf FILE2.pdf OUTPUT.pdf

Merge Specific Pages Into One PDF File

Note: The count of the pages starts from zero.

For this we will pass our filenames with the required page numbers in the square brackets to the convert command.

Merge the second page from the first file FILE1.pdf with the first and the sixth pages from the second file FILE2.pdf and save the result to the new OUTPUT.pdf file:

$ convert FILE1.pdf[1] FILE2.pdf[0,5] OUTPUT.pdf

Join Ranges of Pages Into Single PDF File

And of course it is possible to join some ranges of pages.

Cool Tip: Plan to send this PDF somewhere or just keep? How about to protect it with a password? This is really easy for ones who merge PDF files from the command line! Read more →

Join the first ten pages from first file FILE1.pdf with the first five pages from the second file FILE2.pdf and save the result to the new OUTPUT.pdf file:

$ convert FILE1.pdf2 FILE2.pdf3 OUTPUT.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).

Читайте также:  Linux команда посмотреть видеокарты

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!

    Источник

    Merge PDF Files on Linux: A Comprehensive Guide to Shell Concatenate PDF Files

    Easily merge PDF files on Linux using popular command-line utilities like pdftk, pdfunite, and ImageMagick. Learn how to automate the process with a shell script. Follow our step-by-step guide now!

    • Command-line utilities for merging PDF files
    • Merging PDF files using pdftk
    • How to merge PDF files in Linux
    • Merging PDF files using pdfunite
    • Merging PDF files using ImageMagick
    • Automating the process of merging PDF files
    • Other shell code samples for merging PDF files on Linux
    • Conclusion
    • How to combine two PDF files in Linux?
    • How do you concatenate PDF files?
    • How to combine two PDF files in command prompt?
    • How do I combine multiple PDF files into one in Ubuntu?

    If you are a Linux user and need to combine multiple PDF files into one, you will be pleased to know that there are several command-line utilities available for merging PDF files. In this guide, we will provide step-by-step guidance on how to use some of the popular tools available for merging PDF files on Linux. Whether you need to merge two or more PDF files or automate the process using a shell script, this guide has got you covered.

    Command-line utilities for merging PDF files

    Linux offers several command-line utilities for merging PDF files, including pdftk , pdfunite , ImageMagick , qpdf , and pdfconcat . These tools provide different features and functionalities for merging PDF files, based on the user’s requirements. In the following sections, we will provide detailed instructions on how to use pdftk , pdfunite , and ImageMagick .

    Merging PDF files using pdftk

    pdftk is a versatile and popular tool for merging, splitting, and manipulating PDF documents on Linux. To merge PDF files using pdftk , the user needs to install the utility and follow a few simple steps to concatenate the files into one.

    First, install pdftk using the package manager of your Linux distribution. For instance, in Ubuntu or Debian-based systems, you can use the following command:

    sudo apt-get install pdftk 

    Next, navigate to the directory where your PDF files are stored and run the following command to merge them:

    pdftk file1.pdf file2.pdf . cat output merged_file.pdf 

    This command will merge the PDF files file1.pdf , file2.pdf , and so on, into a single PDF file named merged_file.pdf .

    If you need to specify the order of the pages in the merged PDF file, you can use the shuffle option followed by the page numbers in the desired order. For instance, to merge two PDF files with the first file’s pages first and the second file’s pages second, you can use the following command:

    pdftk A=file1.pdf B=file2.pdf shuffle A B output merged_file.pdf 

    This command will merge the PDF files file1.pdf and file2.pdf into a single PDF file named merged_file.pdf , with the pages in the order A1, A2, . An, B1, B2, . Bm .

    How to merge PDF files in Linux

    Do you have a PDF file you wish to combine with another one? Have you tried other merging Duration: 2:17

    Merging PDF files using pdfunite

    pdfunite is another command-line utility for merging PDF files that is part of the poppler-utils package. This tool is particularly useful for merging PDF files with similar names or based on their numerical order. To merge PDF files using pdfunite , the user needs to install the utility and follow a few simple steps to concatenate the files into one.

    First, install poppler-utils using the package manager of your Linux distribution. For instance, in Ubuntu or Debian-based systems, you can use the following command:

    sudo apt-get install poppler-utils 

    Next, navigate to the directory where your PDF files are stored and run the following command to merge them:

    pdfunite file1.pdf file2.pdf . merged_file.pdf 

    This command will merge the PDF files file1.pdf , file2.pdf , and so on, into a single PDF file named merged_file.pdf .

    If you need to specify the order of the pages in the merged PDF file, you can use the cat option followed by the page numbers in the desired order. For instance, to merge two PDF files with the first file’s pages first and the second file’s pages second, you can use the following command:

    pdfunite file1.pdf file2.pdf cat output merged_file.pdf 

    This command will merge the PDF files file1.pdf and file2.pdf into a single PDF file named merged_file.pdf , with the pages in the order file1.pdf(1), file1.pdf(2), . file1.pdf(n), file2.pdf(1), file2.pdf(2), . file2.pdf(m) .

    Merging PDF files using ImageMagick

    ImageMagick is primarily used for image optimization but also includes a conversion tool that can merge PDF files. To merge PDF files using ImageMagick , the user needs to install the utility and follow a few simple steps to concatenate the files into one.

    First, install ImageMagick using the package manager of your Linux distribution. For instance, in Ubuntu or Debian-based systems, you can use the following command:

    sudo apt-get install imagemagick 

    Next, navigate to the directory where your PDF files are stored and run the following command to merge them:

    convert file1.pdf file2.pdf . merged_file.pdf 

    This command will merge the PDF files file1.pdf , file2.pdf , and so on, into a single PDF file named merged_file.pdf .

    If you need to specify the order of the pages in the merged PDF file, you can use the -density and -define options followed by the page numbers in the desired order. For instance, to merge two PDF files with the first file’s pages first and the second file’s pages second, you can use the following command:

    convert -density 300 -define pdf:use-trimbox=true file1.pdf[1-n] file2.pdf[1-m] merged_file.pdf 

    This command will merge the PDF files file1.pdf and file2.pdf into a single PDF file named merged_file.pdf , with the pages in the order file1.pdf(1), file1.pdf(2), . file1.pdf(n), file2.pdf(1), file2.pdf(2), . file2.pdf(m) .

    Automating the process of merging PDF files

    For those who need to perform the task of merging PDF files frequently, it is possible to automate the process using a shell script. In this section, we will provide guidance on how to create a shell script to automate the process of merging PDF files, including setting the correct order and creating bookmarks and table of contents in the final document.

    First, create a new file named mergepdf.sh and add the following code:

    #!/bin/bash# Set the working directory cd /path/to/pdf/files# Merge the PDF files into one pdftk file1.pdf file2.pdf . cat output merged_file.pdf# Create bookmarks and table of contents pdftk merged_file.pdf dump_data output info.txt sed -i '/NumberOfPages/d' info.txt sed -i '/BookmarkPageNumber/d' info.txt sed -i '/BookmarkLevel/d' info.txt sed -i '1i\BookmarkBegin' info.txt sed -i '$a\BookmarkEnd' info.txt pdftk merged_file.pdf update_info info.txt output final_file.pdf# Remove temporary files rm merged_file.pdf info.txt 

    Make sure to replace /path/to/pdf/files with the path to the directory where your PDF files are stored. Also, replace file1.pdf , file2.pdf , and so on, with the names of the PDF files you want to merge.

    This shell script will merge the PDF files into one using pdftk , create bookmarks and a table of contents using the dump_data and update_info commands, and remove the temporary files.

    Save the file and make it executable using the following command:

    Now, you can run the shell script anytime to merge your PDF files.

    Other shell code samples for merging PDF files on Linux

    In Shell , for example, how to concat pdf linux code example

    pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf

    Conclusion

    Merging or concatenating multiple PDF files into one can be easily accomplished on Linux using various command-line utilities such as pdftk , pdfunite , and ImageMagick . Each tool provides different features and functionalities for merging PDF files, based on the user’s requirements. By following the step-by-step guidance provided in this guide, users can easily merge PDF files and automate the process using a shell script. With this comprehensive guide, you can now merge your PDF files on Linux with ease.

    Источник

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