2025-05-12 17:47:32 +02:00
2025-05-12 17:47:32 +02:00
2025-05-12 17:47:32 +02:00
2025-05-12 17:47:32 +02:00

impose_booklet

impose_booklet.py is a lightweight Python script that reorders A5 single pages from a PDF into booklet signatures for duplex printing on A4 sheets and subsequent folding into A5 booklets. With the latest updates, it also supports border trimming and a Manga mode.

Features

  • Flexible signature size via --sheets N (default: 5 sheets → 20 pages per signature)
  • Automatic padding with blank pages if the total page count isnt divisible by the signature size
  • Correct page arrangement for the front and back of each A4 sheet
  • Border trim via --trim X (in mm): cuts X mm off each edge of every page
  • Skip trim via --skip-trim P1 P2 ...: list of page numbers to exclude from trimming (e.g., title page)
  • Manga mode via --manga-mode: horizontally mirrors the imposition layout for right-to-left reading

Requirements

  • Python 3.7 or newer
  • pypdf (for PDF read/write)
  • pymupdf (for border trim):
pip install pypdf pymupdf

Installation

pip install pypdf pymupdf

Usage

python impose_booklet.py <input.pdf> <output.pdf> [--sheets N] [--trim X] [--skip-trim S1 S2 ...] [--manga-mode]
  • <input.pdf>: path to the source PDF containing A5 single pages
  • <output.pdf>: path for the generated booklet-ready PDF
  • --sheets N / -s N: number of sheets per signature (default: 5)
  • --trim X: border trim in millimeters (default: 0)
  • --skip-trim S1 S2 ...: pages to exclude from trimming (default: 1)
  • --manga-mode: mirror the imposition for right-to-left reading order

Examples

  1. Standard booklet (60 pages, 5 sheets per signature):

    python impose_booklet.py mybook.pdf mybook_booklet.pdf --sheets 5
    
  2. With border trim (10 mm on all edges, title page excluded):

    python impose_booklet.py mybook.pdf mybook_trim.pdf --trim 10 --skip-trim 1
    
  3. Manga mode (right-to-left):

    python impose_booklet.py manga.pdf manga_booklet.pdf --sheets 4 --manga-mode
    
  4. Combined (border trim + Manga mode):

    python impose_booklet.py manga.pdf manga_trim_booklet.pdf --trim 5 --skip-trim 1 --manga-mode
    

How It Works

  1. Load: all A5 pages are read from the input PDF.

  2. Optional border trim: if --trim X is set, every page (except those in --skip-trim) is cropped by X mm on each side.

  3. Calculate: compute pages_per_sig = sheets * 4 and determine how many signatures are needed: ceil(total_pages / pages_per_sig).

  4. Pad: append blank pages so each signature has exactly pages_per_sig pages.

  5. Impose:

    • Normal mode: place pages per sheet in the order: front-left (outermost), front-right (first), back-left (second), back-right (penultimate).
    • Manga mode: horizontally mirror those four slots so the reading order follows right-to-left layout.
  6. Save: write the reordered pages into the output PDF.

Troubleshooting

  • Mixed page sizes: the script uses the MediaBox of the first page as the template for blank pages.
  • No duplex printing: ensure your printer driver supports two-sided printing.

License & Disclaimer

This project is released under the MIT License. No warranty is provided for commercial suitability.


Happy printing and folding!

Description
Lightweight Python script that reorders A5 single pages from a PDF into booklet signatures for duplex printing on A4 sheets and subsequent folding into A5 booklets. With the latest updates, it also supports **border trimming** and a **Manga mode**.
Readme 33 KiB
Languages
Python 100%