- How to Merge PDF Files on Linux
- 1) Using pdfunite
- 2) Using pdftk tool
- 3) Using Convert tool
- 4) Using Ghostscript
- 5) Using pdfsam
- HowTo: Merge PDF Files – Linux Command Line
- Convert Multiple PDF Files Into One
- Merge Specific Pages Into One PDF File
- Join Ranges of Pages Into Single PDF File
- Как объединить несколько PDF-файлов в Linux с PDFtk
- Респект за пост! Спасибо за работу!
- How to merge or split PDF files on Linux
- 1 – Using PDFTK
- 2 – Using QPDF tool
- a – QPDF installation
- b- QPDF syntax
- c – Merging files using QPDF
- d- Collation option in QPDF
- e- Specific pages selection
- 2 PDFUNITE tool
- a – Syntax of PDFUNITE
- b – Merging files using PDFUNITE
- 4 – Using PDFSEPARATE
- a – Syntax of PDFSEPARATE
- b – Options of PDFSEPARATE command tool
- b- Splitting a file using PDFSEPARATE
- 3 – Using PDFSAM
- 4 – Conclusion
How to Merge PDF Files on Linux
Sometimes, you may have 2 or more PDF files that you need to combine or merge into one so that you can have everything in one place. This will minimize time wasted trying to look for your PDF files which may be in different folders and other directories.
Recently I have tested a few tools to merge pdf files on Linux that I will introduce to you today. I have tested all the tools on the Ubuntu 18.04 version.
1) Using pdfunite
Pdfunite is a handy tool that can be used for merging to or more PDF documents. It is part of poppler-utils package, so when you install poppler utils, you end up with pdfunite.
To install pdfunite, we’ll install the poppler-utils package as shown
Sample Output
Next. update the system
In the downloads folder, I have 2 PDF documents
We are going to merge them using pdfunite command.
To merge the PDF documents, the syntax will be as shown
Using our files as shown earlier, the command will be
You will get the following warning in the output, but don’t worry. The files have already been merged.
As you can see, the output file merged_output.pdf has been created
Note: Files to be merged need to be in the same directory where pdfunife is executed
2) Using pdftk tool
Pdftk is yet another tool that can be used to merge PDF documents in Ubuntu 18.04. To install pdftk on terminal in Ubuntu 18.04, first add the pdftk repository
Output
Next, update your Ubuntu System
After successfully updating your system, install the pdftk tool as shown below
After the installation of pdftk is complete, you can now invoke the pdftk command to merge files. The syntax is as shown
using our earlier files, the command will be as shown
3) Using Convert tool
To use the convert command, first install it on terminal using the command below
Output
Upon successful installation, you can now merge your documents.
The syntax for merging 2 PDF files is as shown
Using our files , the command will be
Output
To Merge specific PDF pages into a single PDF file, you’ll need to pass our files with specific page numbers in square brackets to the convert command. For example to merge the 5th page from the first document with 7th and 10th pages in the second document, the syntax will be
Using our files , the command will be
Output
And Yes, it’s very possible to join page ranges.
For Example, you can join the first 5 pages from first file with first 10 pages from the other file. The syntax for this case will be
Using our files , the command will be
4) Using Ghostscript
We can also use ghostscript (gs) to merge PDf documents in Ubuntu 18.04
apt install ghostscript
Example of using ghostscript to merge 2 PDF documents
In the above example, let’s expound further on the attributes
Using our documents earlier, the command will be
Sample Output
5) Using pdfsam
Pdfsam is a simple, intuitive and easy to use GUI tool that is used to merge, split, rotate, edit and sign PDF documents. In this example, we are going to use the tool to merge PDF documents in Ubuntu 18.04. But first, let’s install it
After successful installation, define the JAVA_HOME variable in /etc/environment path using your favorite editor.
Append the following line.
reload the file
Next, download the Debian package file from pdfsam’s official site
Once downloaded, install the deb file using the dpkg command as shown.
Sample Output
To start pdfsam, run
To merge documents, click on ‘Merge’ and drag and drop the files to be merged in the section provided.
Feel free to specify other attributes in the ‘Merge Settings‘ section and once done click on the ‘Run‘ icon located at the bottom. Once done, you’ll hear a ‘ding’ sound notifying you that the merging process is complete.
As seen in the above examples, merging PDF files on Linux is very easy and straight forward on the terminal. Give it a try and let us know how it went. Your Feedback is much welcome in our comment section. Thank you and feel free to share this tutorial on your social handles.
Источник
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:
Convert Multiple PDF Files Into One
Merge two PDF files FILE1.pdf and FILE2.pdf into the new OUTPUT.pdf file:
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:
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 →
Источник
Как объединить несколько PDF-файлов в Linux с PDFtk
PDFtk Server — это инструмент командной строки Linux, позволяющий легко объединять несколько PDF-файлов в один.
PDFtk — это бесплатное программное обеспечение с открытым исходным кодом, доступное для Windows, Linux и MacOS. Лучше всего то, что для его работы не требуется Acrobat или любой другой продукт Adobe.
PDFtk позволяет объединять PDF документы, разбивать PDF страницы на новые документы, вращать PDF страницы, расшифровывать и шифровать, обновлять метаданные, наносить водяные знаки и многое другое.
Примечание: Версия PDFtk Free для Windows поставляется с графическим интерфейсом, где вы можете легко добавить несколько PDF-файлов и объединить их в один.
Для Linux, в Ubuntu, вы можете установить его с помощью команды:
PDFtk также доступен в большинстве репозиториев.
1. После установки pdftk необходимо запустить его из командной строки, поэтому запустите терминал.
2. Перейдите в каталог, содержащий ваши PDF-файлы:
3. Решите, в каком порядке вы хотите, чтобы PDF-файлы появились в окончательном документе. Вы будете использовать этот порядок при наборе команды:
4. Введите следующую команду, указав ваши PDF-файлы в том порядке, в котором вы хотите, чтобы они появились:
Это все, что нужно. Обязательно проверьте новый PDF файл, чтобы убедиться, что все новые страницы отображаются правильно. Процесс слияния является бесшовным, безболезненным и должен работать на любых обычных файлах PDF.
Чтобы скомбинировать несколько документов в каталоге без перечисления каждого из них, используйте знак (*):
В качестве дополнительного бонуса pdftk может выполнять множество других задач. Например, чтобы разделить страницы pdf файла на несколько документов, выполните следующую команду:
При этом документ будет разделен на отдельные страницы, которыми вы сможете управлять по своему усмотрению.
С помощью pdftk вы даже можете объединить определенные страницы из нескольких документов в один новый документ. Просто введите следующую команду:
В этом случае «А» и «В» используются в качестве «обработчиков» названий ваших документов.
Чтобы зашифровать новый PDF-файл, используйте следующую команду:
где «foopass» — это пароль, который вы используете для шифрования файла.
С другой стороны, если у вас есть зашифрованный PDF файл, вы также можете расшифровать его с помощью pdftk:
Вы также можете использовать команду pdftk —help или получить доступ к их онлайн-примерам.
Спасибо, что читаете! Подписывайтесь на мои каналы в Telegram, Яндекс.Мессенджере и Яндекс.Дзен. Только там последние обновления блога и новости мира информационных технологий.
Респект за пост! Спасибо за работу!
Хотите больше постов? Узнавать новости технологий? Читать обзоры на гаджеты? Для всего этого, а также для продвижения сайта, покупки нового дизайна и оплаты хостинга, мне необходима помощь от вас, преданные и благодарные читатели. Подробнее о донатах читайте на специальной странице.
Заранее спасибо! Все собранные средства будут пущены на развитие сайта. Поддержка проекта является подарком владельцу сайта.
Источник
How to merge or split PDF files on Linux
In this short article, you will learn how to merge or split two or more PDF files using command line and GUI based tools. This is suitable for both beginners and experienced Linux users, so let’s get started.
1 – Using PDFTK
PDFTK is a command line tool used to manipulate PDF files. It enables users to carry out several operations on PDF files like splitting, merging, encrypting, decrypting and many more.
For a complete guide on how to install and use PDFTK to merge or split PDF documents on Linux, follow this guide .
2 – Using QPDF tool
QPDF is a lightweight program used to carry out content-preserving and structural transformations on PDF files. It allows to copy objects from one PDF document into another and to handle the list of available pages in a PDF file. This enables the QPDF tool, which has a low dependency on other utilities, to split and merge PDF documents.
Developers of PDF generating applications will find QPDF capabilities very useful indeed. It can also be used to create PDF documents from scratch. QPDF however is not a PDF viewer or a PDF file converter to other formats since it ignores the semantics of PDF files content streams.
a – QPDF installation
In order to install the lightweight QPDF tool, issue the sudo command below :
sudo apt install qpdf
b- QPDF syntax
When invoking qpdf, the basic syntax is as follows :
qpdf [ options ] input_filename [ output_filename ]
This will actually convert the PDF file input_filename to the PDF file output_filename. The output document is identical in functionality to the input file though it may have been reorganized structure wise. The options outlined below will control many transformations on the PDF files. The parameter –empty may be provided, in place of input_filename attribute. if you would like to add pages from another file, you could use the –empty switch .
In the command below, qpdf is called with the –empty switch :
Two new pdf files are created separately by each command.
If @filename has been inserted at any position in the command-line, QPDF will read the filename line by line and treat them as a command line argument. The @ switch enables arguments to be retrieved or read from standard input. This will enabe qpdf to be called with any number of long arguments.
If the output_filename argument contains only “-”, it would tell QPDF to write to standard output. If you want to overwrite or replace the input file with the output document, the option –replace-input should be used along with the output file name omitted.
c – Merging files using QPDF
QPDF gives the possibility to merge and split PDF files by choosing pages from one or many input files. Any single input file given is considered as the primary input file and used as the starting point. This file’s pages will be replaced according to the specification in the arguments of the command.
–pages input-file [ –password=password ] [ page-range ] [ … ] —
It is possible to specify multiple input files. Each one is given an optional password if it is password-protected as well as the range of pages. The “–” indicates that the parsing of page selection flags is finished.
In order to merge PDF files into one single file, the following command should be executed
[merge pdf linux command] :
qpdf –empty output_merged.pdf –pages input_file1.pdf input_file2.pdf
Where the files input_file1.pdf and input_file2.pdf will be merged into the PDF document ouput_merged.pdf .
If you wanted to merge all pdf files in the current directory into one single output file, you should run the command below :
qpdf –empty output_file.pdf –pages *.pdf — [pdf merge linux]
d- Collation option in QPDF
When the option –collate is specified, the meaning of the option –pages will change so that the specified input files are collated instead of concatenated as modified by page ranges . For instance, if you add the two files odd.pdf and even.pdf where odd.pdf contains odd pages of a document whereas even.pdf contains the even pages, the command :
qpdf –collate –pages odd_file.pdf even_file.pdf — all.pdf
will collate the pages. The output will result in the picking page 1 from odd_file.pdf then page 1 from even_file.pdf, next would be page 2 from odd_file.pdf and then page 2 from even_file.pdf and so forth until all pages from both files have been included. It is possible to specify any number of files or page ranges. If any file has less pages than others, it will be skipped once all its pages have been included.
e- Specific pages selection
In order now to pick pages 1-7 from an input file named input_file.pdf while all metadata associated with that file is preserved, run the command below :
qpdf input_file.pdf –pages 1-7 — outfile.pdf
If you wanted pages 1 through 5 from infile.pdf but you wanted the rest of the metadata to be dropped, you could instead run
qpdf –empty –pages infile.pdf 1-5 — outfile.pdf
2 PDFUNITE tool
PDFUNITE is a utility that is part of the package poppler-utils, which means that you will get PDFUNITE when you install the package poppler-utils. After the installation is completed, you can immediately start merging your PDF files.
a – Syntax of PDFUNITE
PDFUNITE has a pretty simple syntax :
pdfunite [options] Inputfile1.pdf Inputfile2.pdf .. MergedFile.pdf
Where the files Inputfile1.pdf, Inputfile2.pdf .. are the source files whereas the merged file should be placed at the end of the command line, i.e. MergedFile.pdf .
b – Merging files using PDFUNITE
In order to merge PDF files into one single PDF document, the following command should be used (Ubuntu pdf merge command) :
pdfunite InputFile1.pdf InputFile2.pdf InputFile3.pdf merged_File.pdf
The input files need to belong to the same directory where PDFUNITE is executed. If your PDF files belong to different folders, you would have to provide the absolute path.
4 – Using PDFSEPARATE
Much like its PDFUNITE, PDFSEPARATE is also a unit of the package poppler-utils.
a – Syntax of PDFSEPARATE
The utility PDFSEPARATE has the following syntax:
pdfseparate [options] InputFile.pdf OutputFile_Pattern
PDFSEPARATE reads the input file InputFile.pdf and breaks it up into one or more PDF file OutputFile_Pattern each of which contains one page.
The OutputFile_Pattern should contain the wildcard %d which will be replaced by the page number at the end of the operation. The input file should not be password protected.
b – Options of PDFSEPARATE command tool
There are mainly two options in the PDFSEPARATE utility :
-f number : Indicates the first page to be extracted. If omitted, the extraction will start with the first page or page 1.
-l number : Indicates the last page to be extracted. Extraction ends with the last page if omitted.
b- Splitting a file using PDFSEPARATE
The following command :
pdfseparate InputFile.pdf InputFile-%d.pdf
Would tell PDFSEPARATE to extract the entire pages from InputFile.pdf to as many files as the number of pages .i.e. if InputFile.pdf has 4 pages, there will be 4 files :
InputFile-1.pdf, InputFile-2.pdf, InputFile-3.pdf and InputFile-4.pdf
3 – Using PDFSAM
Not only command tools can carry out the merging and splitting of PDF files but other GUI based utilities can do the job as well. One of these applications is PDFSAM. It has the possibility to perform many other operations as well like rotating and extracting pages, splitting bookmarks and many others. PDFsam is a Java based tool which is available in most Linux distros. Its GUI is rather intuitive, simple and self-explanatory. For Ubuntu / Debian, you can run the APT command below in order to install PDFsam:
sudo apt-get install pdfsam
Once finished, just invoke the command :
This will being up the popup below which indicates that the application is starting up :
Finally PDFSAM graphical interface will show up as shown below :
Once you click on ‘Merge’ button, the following window will pop up:
Click on the ’Add’ button to select the input PDF files you want to merge. Next scroll down to the ‘Destination file’ section and click the ‘Browse’ button:
You will be able to select a location and a filename for the merged PDF file. Finally Click on ‘Run’ button and you are done !
To split a document, just click on the ‘Split’ button in the main interface :
The principle is the same here as in the previous section but in this case, you would need to choose the file to be broken up using the file browser. Next you would need to select the ‘Split settings’ before selecting the output directory where the splitted files would be generated. Finally click on ‘Run’ button.
4 – Conclusion
You have seen how to merge and split PDF documents using command line based tools like PDFTK, PDFUNITE, PDFSEPARATE and QPDF. For those who do not feel at ease handling commands, they can choose PDFSAM which is a GUI based utility.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.
Источник