#!/usr/bin/env bun import { PDFDocument } from "pdf-lib"; import * as fs from "fs"; import * as path from "path"; import minimist from "minimist"; // Types interface SplitOptions { output: string; pages: string; chunkSize: number; even: boolean; odd: boolean; first: number | null; last: number | null; reverse: boolean; naming: string; startNumber: number; padDigits: number; } // Parse command line arguments const args = minimist(process.argv.slice(2), { string: ["output", "pages", "naming"], boolean: ["even", "odd", "reverse", "help"], default: { output: "./split/", pages: "all", "chunk-size": 1, even: false, odd: false, reverse: false, naming: "page-{n}", "start-number": 1, "pad-digits": 3, }, alias: { o: "output", p: "pages", h: "help", }, }); // Show help if (args.help || args._.length === 0) { console.log(` Split PDF - Split PDF files into pages or ranges Usage: skills run split-pdf -- [options] Options: -o, --output Output directory or file (default: ./split/) -p, --pages Pages to extract: "1-5", "1,3,5", "all" (default: all) --chunk-size Pages per output file (default: 1) --even Extract even pages only --odd Extract odd pages only --first Extract first N pages --last Extract last N pages --reverse Reverse page order --naming