28 lines
1.6 KiB
Markdown
28 lines
1.6 KiB
Markdown
# pdf-segmented
|
|
|
|
Generate PDFs (or DjVu) using separate compression for foreground and background
|
|
|
|
## Usage
|
|
|
|
```
|
|
python -m pdf_segmented input.xcf output.pdf
|
|
```
|
|
|
|
Takes as input a [GIMP](https://www.gimp.org/) XCF file with one layer per page (bottom layer = first page).
|
|
|
|
All black pixels (#000000) will be considered to be foreground, and all remaining pixels will be considered to be background. This is most easily accomplished by selecting all colour graphics in GIMP, inverting the selection (Ctrl+I), then applying the [Threshold tool](https://docs.gimp.org/3.0/en/gimp-tool-threshold.html).
|
|
|
|
The foreground will be compressed losslessly using [JBIG2](https://en.wikipedia.org/wiki/JBIG2). The background will be compressed lossily using [JPEG](https://en.wikipedia.org/wiki/JPEG). JPEG quality can be controlled using the `--jpeg-quality` option; the default is the Pillow default (75% at time of writing).
|
|
|
|
Additional compression algorithms are supported (JPEG 2000, PNG); see `--help` for detailed options. DjVu output (foreground JB2, background IW44) is also supported.
|
|
|
|
## Dependencies
|
|
|
|
* [Python 3](https://www.python.org/) (tested using 3.13.3)
|
|
* [NumPy](https://numpy.org/) (tested using 2.2.5)
|
|
* [Pillow](https://pillow.readthedocs.io/en/stable/) (tested using 11.2.1)
|
|
* [pikepdf](https://pikepdf.readthedocs.io/en/latest/) (tested using 9.7.0)
|
|
* [DjVuLibre](https://djvu.sourceforge.net/) (tested using 3.5.28) – for DjVu output
|
|
* [ImageMagick](https://imagemagick.org/) (tested using 7.1.1.47)
|
|
* [jbig2enc](https://github.com/agl/jbig2enc) (tested using 0.30) – for JBIG2
|