🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.linux.misc
Article #2585

Re: Shrinking huge PDF files

#2585
From: 🇵🇱Jacek Marcin Jaworski🇵🇱
Date: Sun, 15 Nov 2026 02:26
90 lines
5148 bytes
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>.
Technical Details
Message-ID: <IdKdnRDIs8f9hWT3nZ2dnZfqn_idnZ2d@giganews.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!local-4.nntp.ord.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <Qq7KS.9052$s53.4981@fx10.iad>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!local-4.nntp.ord.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 15 Nov 2026 02:26:40 +0000
Date: Sun, 15 Nov 2026 03:26:30 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Shrinking huge PDF files
Newsgroups: comp.os.linux.misc
References: <Qq7KS.9052$s53.4981@fx10.iad>
Content-Language: pl-PL, en-GB
From: 🇵🇱Jacek Marcin Jaworski🇵🇱
 <jmj@energokod.gda.pl>
Organization: energokod.gda.pl
In-Reply-To: <Qq7KS.9052$s53.4981@fx10.iad>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <IdKdnRDIs8f9hWT3nZ2dnZfqn_idnZ2d@giganews.com>
Lines: 90
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-pAcf6L6Y+f/eSqh0CoE9uckpSXQl2Wq6I23T/KU9AdBcZ7bg1TqC9C5Y60ZBI7+V4/+ftOc5ZfclItQ!Me407yPhzHtyzYIptNXEke0ZvxW4WCai4sAUpxX9MQYW0rldoRRu3Uzx159gU2kNaehfaWqC
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40