Got a scanned book PDF that’s crooked and bulky? You want to straighten (deskew) the pages and shrink the file size, ideally by converting images inside to a modern format like AVIF? Let’s break down a practical workflow on Debian without ScanTailor (since it’s not in the repos):
1. Deskew / Straighten the scanned pages
Since ScanTailor isn’t available, here are some alternatives:
-
unpaper — a command-line tool designed for post-processing scanned pages. It can deskew, clean, and crop pages.
Install it on Debian:
sudo apt install unpaper
Usage example:
unpaper --deskew input.pdf output.pdf
Note: unpaper works best on single-page images, so you might need to split your PDF into images first.
-
mupdf / mutool — can extract pages as images.
-
pdfimages (from poppler-utils) — extract images from PDF.
2. Extract pages as images
You can convert PDF pages to images (e.g., PNG) using pdftoppm:
pdftoppm -png input.pdf page
This creates page-1.png, page-2.png, etc.
3. Deskew images with unpaper
Run unpaper on each image or batch process:
unpaper --deskew page-1.png page-1-deskewed.png
Or batch with a loop:
for img in page-*.png; do
unpaper --deskew "$img" "deskewed/$img"
done
4. Convert images to AVIF
AVIF is a modern, efficient image format that can reduce file size significantly.
Install avifenc (from libavif-tools):
sudo apt install libavif-tools
Convert PNG to AVIF:
avifenc deskewed/page-1.png deskewed/page-1.avif
Batch convert:
mkdir avif
for img in deskewed/*.png; do
avifenc "$img" "avif/$(basename "${img%.png}.avif")"
done
5. Rebuild PDF from AVIF images
Use img2pdf (supports AVIF):
sudo apt install img2pdf
Create PDF:
img2pdf avif/*.avif -o output.pdf
6. Optional: Compress PDF further
Use ghostscript to compress PDF:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
-dNOPAUSE -dQUIET -dBATCH -sOutputFile=output-compressed.pdf output.pdf
Summary workflow:
# 1. Extract pages as PNG
pdftoppm -png input.pdf page
# 2. Deskew images
mkdir deskewed
for img in page-*.png; do
unpaper --deskew "$img" "deskewed/$img"
done
# 3. Convert to AVIF
mkdir avif
for img in deskewed/*.png; do
avifenc "$img" "avif/$(basename "${img%.png}.avif")"
done
# 4. Rebuild PDF
img2pdf avif/*.avif -o output.pdf
# 5. Compress PDF (optional)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
-dNOPAUSE -dQUIET -dBATCH -sOutputFile=output-compressed.pdf output.pdf
Alternative GUI tools:
gscan2pdf — GUI tool for scanning and cleaning PDFs, supports deskew and compression.
OCRmyPDF — can deskew and optimize scanned PDFs, but mainly for OCR.
If you want me to help with a script or more detailed steps, just ask!