pdfsplit is a Ruby CLI tool that splits a multi-page PDF into smaller PDF files with a fixed number of pages per part.
- Cross-platform: Linux / macOS / Windows
- No external PDF utilities required (no
pdftk,qpdf, etc.) - Uses the HexaPDF gem to handle PDF files
- Splits
input.pdfinto files likeinput_part001.pdf,input_part002.pdf, ... - Part size is configured via
--pages N - Output directory is configured via
--out DIR(defaults to current directory.) --help,--version- Clear error messages and proper exit codes (0 = success, 1 = error)
- Ruby 3.1+ (recommended)
Bundler is only needed for development / running from the repository.
After installing the gem, you can run thepdfsplitcommand directly.
gem install pdfsplitAfter installation the executable becomes available:
pdfsplit --helpOn Windows, if the
pdfsplitcommand is not found, ensure RubyGems' bin directory is in yourPATH(RubyInstaller usually sets this up automatically).
Clone the repository and install dependencies:
bundle installInstalled gem (recommended):
pdfsplit input.pdf --pages 10From repository:
bundle exec pdfsplit input.pdf --pages 10Outputs will be created in the current directory:
input_part001.pdfinput_part002.pdf- ...
pdfsplit INPUT.pdf --pages 10 --out outFiles will be created in out/.
pdfsplit --helppdfsplit --versionGiven an input file input.pdf, the tool writes:
input_part001.pdfinput_part002.pdfinput_part003.pdf- ...
- Missing input file → exit 1 + Usage
- Missing
--pages/--pages <= 0→ exit 1 + Usage - More than one input file provided → exit 1 + Usage
- Input file does not exist → exit 1 + OS error message
- Input is not a valid PDF → exit 1 + Error: invalid PDF
--outpoints to an existing file → exit 1 + Error:--outmust be a directory- Output directory is not writable → exit 1 + OS error message
Run tests:
bundle exec rspecInstall the gem locally (to test it as an installed gem):
bundle exec rake installOpen an interactive console (Bundler-generated helper):
bin/consoleMIT License