C++17 · Ghostscript · Single executable

PDFs, merged.
Not just glued together.

File Merger scans a folder, sorts every PDF the way you actually want — including numeric filenames in the right order — and hands the whole stack to Ghostscript for a properly structured single file.

C++17, one source file Ghostscript pdfwrite Numeric-aware sort Windows · Linux · macOS

Despite the repo's name, it's PDF-only for now — generic file support is an open idea.

Numeric sort, done right

2 comes before 10. Obviously.

Alphabetical sort treats filenames as text — "10.pdf" comes before "2.pdf" because "1" is less than "2". File Merger compares the numbers themselves.

Scroll to watch handout_2 through handout_11 fall into actual numeric order.

See it run

Two questions, one file.

./FileMerger Choose merge order: 1 - Alphabetical (numeric names sorted correctly) 2 - Last modification date Selection: 1 Choose sort direction: 1 - Ascending 2 - Descending Selection: 1 Merging 5 files... Done. Output saved as merged_output.pdf.
Why it's built this way

Three calls worth explaining.

01

C++, not Python

A single self-contained executable that other students sharing the same handout folders can run without installing a Python interpreter or any packages.

02

Ghostscript, not a PDF library

pdfwrite re-renders and recompresses every page into a structurally valid, linearized file. Raw byte concatenation opens fine in most viewers but fails PDF/A checks and can corrupt cross-reference tables — for notes you might need to submit or print, that matters.

03

std::system(), not linked libgs

Linking Ghostscript's C API complicates the build and ties the binary to one installed version. Shelling out keeps it a single-file compile, at the cost of a slightly slower startup — fine for a batch tool.

Get started

Build it, drop it in a folder, run it.

01

Clone the repository

git clone https://github.com/mirconegri/FileMerger.git
02

Verify Ghostscript is on PATH

gs --version on Linux/macOS, or gswin64c --version on Windows.

03

Build it

Linux / macOS
g++ -std=c++17 PdfMerger.cpp -o FileMerger
Windows, MinGW
g++ -std=c++17 PdfMerger.cpp -o FileMerger.exe
Windows, MSVC
cl /std:c++17 PdfMerger.cpp
04

Run it

Drop the executable in a folder of PDFs, run ./FileMerger, and answer the two prompts.

Built in the open, one folder of scans at a time.

Look at the code, suggest generic (non-PDF) support, or open an issue.