Z totaliztycznym salutem!
NOTE: THIS IS ONLY DESCRIPTION "HOW TO CREATE HIGHLY COMPRESSED BLACK-AND-WHITE PDFS". SO IT IS UP TO YOU WRITE YOUR OWN USABLE SHELL SCRIPT!!! BECAUSE IT IS INFO FOR CLEVER HACKERS NOT FOR LAZY AND BRAINLESS LAMERS!!! THIS BROCHURE INTENTIONALLY RESPECT PROVERB: "A WORD TO THE WISE IS SUFFICIENT."
Originally this was brochure written in polish "Skanowanie i Tworzenie Dok. PDF w Sys. Debian Ubuntu", chapter "4.1 Tworzenie Czarnobiałych Dok. PDF". This brochure is available as a PDF eBook from my WWW home page. It is available for free (as in "free beer").
<https://energokod.gda.pl/monografie/Skanowanie%20i%20Tworzenie%20Dok.%20PDF%20w%20Sys.%20Debian-Ubuntu.pdf>
Translation was generated today by ChatGPT (OpenAI, GPT6):
> ## 4.1 Creating Black-and-White PDF Documents
>
> Official documents, many university lecture notes, and numerous books are published in black and white. This makes it possible to significantly reduce the size of the resulting PDF document.
>
> The process of creating a PDF document consists of several steps:
>
> 1. Converting PNG files to PBM;
> 2. Converting PBM files to DJVU;
> 3. Combining all DJVU files into a single DJVU file;
> 4. Converting the resulting DJVU file into the final PDF file.
>
> Conversion to DJVU is necessary because this format currently provides the best compression for scanned images containing text. Conversion to PBM is necessary because this is the input format accepted by the `cjb2` program, which generates DJVU files.
>
> ```bash
> # To convert PNG files to PBM, call the following
> # command in a loop:
> convert "$lPNG" "$lPBM"
> ```
>
> Of course, you must assign the names of the files being converted to the `lPNG` and `lPBM` variables.
>
> ```bash
> # To convert PBM files to DJVU, call cjb2
> # (Simple DjVuBitonal encoder) in a loop:
> cjb2 -clean "$lPBM" "$lDJVU"
> ```
>
> Of course, you must assign the names of the files being converted to the `lPBM` and `lDJVU` variables.
>
> ```bash
> # To merge individual DJVU files into a single
> # temporary file named tmp.djvu:
> djvm -c "./tmp.djvu" $(find . -maxdepth
> 1 -type f -iname '*.djvu' | nsort)
> ```
>
> `nsort` is my own utility, which sorts filenames by their numeric values rather than by their ASCII codes.
>
> As an alternative, you can use the standard system `sort` command, provided that you use filenames with leading zeros, e.g. `00001.png`, `00002.png`, and so on.
>
> ```bash
> # To convert the merged DJVU file to PDF:
> ddjvu -format=pdf -quality=150
> "./tmp.djvu" "$gNazwaPDF"
> ```
>
> `-quality=150` provides the best quality.
>
> For testing purposes, I scanned the first four pages of an article entitled "The Return of Kakuro", from issue 77 (1/2025) of the two-colour magazine *Świat Matematyki*.
>
> To demonstrate the effectiveness of the compression, I also combined the PNG files into a PDF using the following command:
>
> ```bash
> convert $(find . -maxdepth 1 -type f -
> iname '*.png' | nsort) 'Powrót Kakuro.v2.pdf'
> ```
>
> The resulting files had the following sizes:
>
> ```text
> 256975 'Powrót Kakuro.pdf'
> 637496 'Powrót Kakuro.v2.pdf'
> 154399 'Powrót Kakuro.djvu'
> ```
>
> This means that the resulting `Powrót Kakuro.pdf` file was 166% larger than the DJVU version, while the lossless version was 248% larger.
--
Z totaliztycznym salutem!
Jacek Marcin Jaworski, Pruszcz Gd., woj. Pomorskie, Polska 🇵🇱, UE 🇪🇺;
Pryw. s. WWW: <https://energokod.gda.pl>; Pryw. tel.: +48-609-170-742;
Netykieta: <https://energokod.gda.pl/Netykieta.html>.