I have a large black and white pdf scan of a book. The book is 1700 pages, and is about 300MB. That is about 150-175kb per page. This strikes me as rather large. Two arbitrarily selected pages are attached to illustrate; they are each about 330kb. Running them through ImageMagick's compressor gives pages which are about 240kb, which I think is still too high. The best I've been able to get is about 33% smaller. Very good but still very bad in absolute terms.

I believe the book is simply a bunch of .png's stitched together with no more information than that. I have tried converting to a lower dpi, but it really decreases readability beyond 300. I am confident there is to be a way to convert these files to some kind of document (either .pdf or .djvu), but I don't know how to do this. I tried converting to .tif and that was very useful.

I have done some research and it seems that it might be helpful to run these images through some kind of OCR text recognition software, or otherwise construct "vectorized" text. Can anyone help me with a recommendation of an open source tool for this and some instructions on how to get started?

enter image description here

  • 1
    It should be noted that OCR is flaky at the best of times, and that it will fail badly on the example image. Some OCR programs might try to preserve bold styles and indenting, and others might try to preserve the 2-column, but none I've had experience with will manage to get all the styles... which are fundamental to the nature of a dictionary. One misplaced pronunciation character, and that's useless. Without the formatting, you can't even distinguish entries from definitions. If this is ever published digitally, it will need the publisher's original electronic files or to be transcribed.
    – John O
    Jul 12, 2021 at 16:59

3 Answers 3


Try searching for compressing PDFs in general. I personally use these:

pdftk in.pdf output out.pdf compress


pdf-compress-gray () {
    local input="${1}"
    local out="${2:-${input:r}_cg.pdf}"
    local dpi="${pdf_compress_gray_dpi:-150}"
    gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -sProcessColorModel=DeviceGray -sColorConversionStrategy=Gray -dOverrideICC -dDownsampleColorImages=true -dDownsampleGrayImages=true -dPDFSETTINGS=/screen -dColorImageDownsampleType=/Bicubic -dColorImageResolution=$dpi -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=$dpi -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=$dpi -sOutputFile="$out" "$input"


Your PDF looks botched. I entirely concur with @JohnO on his initial comment. There's almost zero chance that with any of the current OCR techniques, you'd get a satisfying result. However, given the content you show, I'm pretty sure you can obtain a perfectly searchable PDF copy of this book.

Approach 1: Going the 'OCR' way

Having said that, you can use tesseract for OCR. Don't forget to specify both the eng and fra language in on invoking tesseract. Or use one of the derived scripts to add a searchable text layer into the PDF:

Approach 2: Going the 'Compression' way

If you want to go along the path of compressing the PDF, you probably need to play with sampling methods, given that you stated that simply changing DPI didn't necessarily do the trick. One approach using ghostscript is as follows (bash needed, works on wsl as well):

#!/usr/bin/env bash

# Parametrization : https://www.ghostscript.com/doc/current/VectorDevices.htm#distillerparams
# Display defaults: gs -q -dNODISPLAY -c ".distillersettings /screen get {exch ==only ( ) print ===} forall quit" | sort

: ${QFACTOR:="0.4"}
: ${RES:="150"}


gs \
  -o $output \
  -sDEVICE=pdfwrite \
  -dPDFSETTINGS=/screen \
  -dCompatibilityLevel=1.8 \
  -dDetectDuplicateImages=true \
  -dAutoRotatePages=/None \
  -dEmbedAllFonts=false \
  -dSubsetFonts=true \
  -dConvertCMYKImagesToRGB=true \
  -dCompressFonts=true \
  -dColorImageDownsampleType=/Bicubic \
  -dColorImageResolution=${RES} \
  -dGrayImageDownsampleType=/Bicubic \
  -dGrayImageResolution=${RES} \
  -dMonoImageDownsampleType=/Bicubic \
  -dMonoImageResolution=${RES} \
  -dQUIET \
  -dBATCH \
  -dCompressPages=true \
  -c "<< /ColorImageDict << /QFactor ${QFACTOR} /Blend 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >> >> setdistillerparams" \
  -c '<</AlwaysEmbed [ ]>> setdistillerparams' \
  -c '<</NeverEmbed [/Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic /Symbol /ZapfDingbats /Arial]>> setdistillerparams' \
  -f $input

In any case, unless you're ready to delve very deep into the PS/PDF/compression/OCR world, it probably is best to get a better electronic copy of the book, or upload the PDF somewhere for us to look at it.


If you want to maintain the content integrity of your document, I advise against OCR. I think most OCR engines would have a lot of trouble vectorizing your content, due to the heavy use of symbols, mixed use of italics, bold and normal fonts, and complex formatting.

If you simply want to make the final PDF file smaller, you could always compress it using a simple file compression utility available on your computer. For example, within Windows, you could right-click on your file and select "Send to" --> "Compressed (zipped) folder". I've found that does a fairly good job of compressing PDFs. Of course, the downside is that you'll need to uncompress it when you want to read your PDF.

  • In this case zip will not compress it much as the pdf consists of images which format is already compressed
    – mmmmmm
    Nov 6, 2021 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.