Combine PDF files into a password-protected PDF

A free-to-use command-line utility to combine multiple PDF files into a single password-protected PDF

Combine PDF files

Motivation

I needed an easy-to-use command-line utility which would combine multiple PDF files producing a password-protected output file.

When working on the ODS Cover Sheet tool, I needed to combine the cover sheet with all the letters intended for that NHS organisation so the user had a single PDF file they could print in one easy step.

As the printing process used duplex printing, each new patient’s letter needed to start on an even page within the output file so that the start of one letter would not be on the reverse of the preceding letter. This tool can add blank pages as necessary so that each input file always starts on an even page in the output file.

Configuration

The command-line tool is configured via a file called combine.xml. An example of the file is shown below.

The intention is that another process would automate the creation of the combine.xml based on its knowledge of which input files need combining. That process would then call the combine-pdf executable to generate the output file.

The utility reads the combine.xml file on start-up and uses it to configure the password. It also uses the make-page-count-even setting to determine if it should insert blank pages between files to ensure each new file added to the combined PDF starts on the even side.

 1<?xml version="1.0"?>
 2<combine>
 3    <pdf>
 4        <make-page-count-even>yes</make-page-count-even>
 5        <user-password>Pa$$w0rd</user-password>
 6        <filename>output.pdf</filename>
 7    </pdf>
 8    <files>
 9        <file>/path/to/files/input-01.pdf</file>
10        <file>/path/to/files/input-02.pdf</file>
11        <file>/path/to/files/input-03.pdf</file>
12    </files>
13</combine>

Executing

Executing the command line combine-pdf will produce the following output as it processes each input file. On completion the output file specified in the filename node of the XML file will have been created and password protected with the password specified in the user-password node.

1./combine-pdf.exe
2
3Combine PDF
4https://bradley.software/combine-pdf/
5version 1.01
6-----------------------------------------
7Pages : 1 : /path/to/files/input-01.pdf
8Pages : 2 : /path/to/files/input-02.pdf
9Pages : 4 : /path/to/files/input-03.pdf

Download

The ZIP file contains 64-bit binaries for Windows and Linux:

Language

Written and compiled in Go 1.23.0

Source Code Availability

None at the moment. Later, it could be released under the MIT license.

Future Plans

Version History