Menu Close

Merge PDF in Command Line

If you are looking for a command-line tool that can merge PDF on Windows, you've come to the right place. This article describes how easily 2PDF can merge PDF files, text files, images, and other filetypes to PDF from the command line interface (CLI). 

2PDF has different ways to combine documents – PDFs, Word, Excel files, images, and other filetypes. You can split, merge (append & prepend), keep "as is" and even extract specific pages. To set the PDF merge option, use a 2PDF command with the multipage attribute: 

2PDF multipage option to merge files via CLI

Multipage options:

  • as is – keep the original file structure
  • split – split multipage files into separate PDF pages
  • prepend – add new files as pages to the beginning
  • append – add new files as pages to the end

How to merge many PDF files into one multipage document

If you have a few or even hundreds of PDF files and you want to join them together, just create a single multipage PDF document containing them all. 

Use this command with multipage:append attribute as an example: 

Run PDF merge from the command line

2PDF.exe -src "E:\Work\PDF\*.pdf" -dst "C:\Out" -pdf multipage:append combine:"my multipage.pdf"

This command will make 2PDF pick up all .pdf files from a defined folder (E:\Work\PDF) and combine them into a single multipage PDF document. The output PDF file with multiple pages will appear in the output folder (C:\Out).

How to merge multiple text files into a single PDF

Imagine a situation when you need to create a single PDF out of various files. They can be, for instance, DOC, DOCX, TXT or RTF documents (or any other supported filetypes). 

Use a command like this:

Merge multiple Word and RTF files into one PDF

2PDF.exe -src "E:\Work\Word DOCX and RTF files\*.*" -dst "C:\Out" -pdf multipage:append combine:"my multipage.pdf"

Here you can optionally restrict input files by file extension. For example, change *.* to *.docx or *.doc.

Press Enter and the process starts: 

2PDF command line batch conversion – Word to PDF

Once the files are merged into one "my multipage.pdf" file, it will appear in the C:\Out folder. 

Compress output PDF to reduce file size (only for Word)

You can also make output PDFs smaller when converting Word documents. 2PDF can help you store files if you save them for archival purposes, e.g., to keep document or correspondence history compact. Precisely for this task, you can use two the min_size option. 

Example command:

2PDF.exe -src "E:\Work\Word DOCX and DOC files\*.*" -dst "C:\Out" -pdf min_size:yes multipage:append combine:"my multipage.pdf"

How to merge many images into one PDF

Pretty much the same way like processing office files, you can combine different images into a PDF. They can be of the same or different formats: JPEG, TIFF, PNG, BMP, GIF, etc. 2PDF has the support for a large number of image types including rare ones. 

Example command: 

2PDF.exe -src "E:\Work\Images\*.*" -dst "C:\Out" -pdf multipage:append combine:"my multipage.pdf"

How to split multipage PDF into separate pages

Splitting PDFs is the opposite of merging – you create many separate files out of a single multipage document. If you want to split one or many multipage files into pages, use the multipage:split attribute. Splitting large files is easy with 2PDF. 

Split PDF into multiple pages using CLI

To do it, use a command like this:

Split a large PDF into pages from command line

2PDF.exe -src "E:\Work\PDF\*.*" -dst "C:\Out" -pdf multipage:split

Extract certain pages

The command above splits the entire source file into pages. But if you need to extract only certain pages, add a page range (pages) to the command. Like this:

2PDF.exe -src "E:\Work\PDF\*.*" -dst "C:\Out" -options pages:1,3-6 -pdf multipage:split

As a result, in this case, you'll get single-page PDF files – only pages 1, 4, 5, 6. 

How to add new pages to an existing PDF 

If you already have a PDF document and want to add more data to it from time to time, you can use multipage:append attribute for this task also. In this case, you'll need to have an existing PDF file "my multipage.pdf" located in the output folder beforehand. Here's an example command:

2PDF.exe -src "E:\Work\PDF\*.*" -dst "C:\Out" -pdf multipage:append combine:"my multipage.pdf"

The new files from the source folder will be added to the existing PDF after using this kind of command. Please note: the existing file must have the same filename as the one you specify for combined file (combine:"my multipage.pdf").

Batch merge to PDF all files listed in a text file

All examples above described how to batch merge files through command line if they are contained in a folder (like E:\Work\PDF in previous cases). There's another feature you can use – specify a TXT with a list of files as a source (-src) instead of indicating a folder path. 

This a handy method especially if:

  • you already have paths to files listed as a text (e.g., generated by other software) 
  • your source files are contained within different folders

For this method, you'll need a file listing as a TXT file. Afterward, execute a command like this:

2PDF.exe -src "@E:\Work\source files list.txt" -dst "C:\Out" -pdf multipage:append combine:"my multipage.pdf"

It doesn't matter if your source files are PDF or of other formats – this works for both cases. 

Don't have a list of file paths yet? Here's how to manually create one

  1. Select the source files you need to convert
  2. While holding Shift, right-click them and select Copy as path:
    Get a list of all files in a folder
  3. Open a newly created TXT file, e.g., "source files list" and paste file paths (Ctrl + V):
    File paths listed in a TXT file
  4. If you have more files to add to the list which located in other folders, repeat the steps 1 and 2 and then add them to the TXT file.

To sum up, we tried to describe as many cases on the topic as we could and provide you with different examples. If you find something tricky or have a specific task which can be potentially solved with 2PDF, please contact our specialists.

Other ways to merge to PDF

If combining files via command line interface is not your cup of tea, we have more PDF merge tools to do it in batch mode, automatically, on schedule or via a virtual printer. Check some other solutions below.


Desktop solution

If you are looking for a simple way to merge PDF without using the command line, but via a graphical interface (GUI), try our another tool – DocuFreezer. It can also merge and split documents.
Learn more →

Virtual printer solution

Virtual printer solution

Another way is to merge files from a virtual printer interface. This way, you can print to PDF using a virtual printer with Append all documents to the existing file or a similar option. Universal Document Converter is a virtual printer that we recommend using.
Learn more →


Server-side solution

If you need a fully automated method to work with files, try a real-time file processor called FolderMill. Based on Hot Folders, it can work on a server or desktop PC. You simply drop files into folders, and FolderMill automatically creates combined PDF files from them.
Learn more →