Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #95708
| From | Nuno Silva <nunojsilva@invalid.invalid> |
|---|---|
| Newsgroups | comp.os.linux.misc |
| Subject | Re: Shrinking huge PDF files |
| Date | 2026-11-16 08:56 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <11degfs$3d3uk$2@dont-email.me> (permalink) |
| References | <Qq7KS.9052$s53.4981@fx10.iad> <%FfKS.6730$5s3.683@usenetxs.com> <NhrKS.21511$li3.13390@fx46.iad> |
On 2026-11-15, Charlie Gibbs wrote:
> Thanks, everyone, for your suggestions. Here's a history of my
> various attempts. To keep things simple, I extracted the first
> page of the 11-page original file (32,468,435 bytes) as follows:
>
> $ pdftk hugefile.pdf cat 1 output testfile.pdf
>
> This resulted in a file of 1,520,696 bytes; the reduction in size is
> a lot more than 11 to 1, so pdftk must be doing some magic of its own.
>
> $ pdfimages -list testfile.pdf
> page num type width height color comp bpc enc interp object ID x-ppi y-ppi size ratio
> --------------------------------------------------------------------------------------------
> 1 0 image 1928 2754 icc 3 8 jpeg yes 6 0 72 72 1481K 9.5%
>
> This indicates colour (icc) with three 8-bit components per pixel.
>
> $ identify testfile.pdf
> testfile.pdf PDF 1944x2772 1944x2772+0+0 16-bit sRGB 9615B 0.010u 0:00.000
>
> Now let's have GhostScript convert the file to grayscale,
> using a suggestion from Nuno Silva:
>
> $ gs -sDEVICE=pdfwrite -sColorConversionStrategy=Gray \
> -sProcessColorModel=DeviceGray -sOutputFile=testfile2.pdf testfile.pdf
>
> This converted the file to grayscale (8 bits per pixel, still with
> JPEG compression; its size is now 359,415 bytes.
>
> Following the URL given by Lawrence D'Oliveiro
> <https://ghostscript.readthedocs.io/gs10.08.0/Devices.html>
> gave a bewildering array of possibilities (the GhostScript
> command "devicenames ==" is even more intimidating).
> Changing the device from pdfwrite to pngmono got the size down
> to 112,386 bytes. The ImageMagick utility "identify" says it's
> 8-bit grayscale.
>
> We're getting the file size down to something more reasonable.
> However, contrast isn't all that good. Let's see whether we
> can go for monochrome.
>
> Working with Rich's suggestions, I ran the following:
> $ gs -sDEVICE=pgmraw -sColorConversionStrategy=Gray \
> -sProcessColorModel=DeviceGray -sOutputFile=testfile3.pgm testfile.pdf
> $ pgmtopbm -threshold -value 0.82 testfile3.pgm | pnmtotiff -g4 >testfile3.tif
> $ tiff2pdf -o testfile3.pdf testfile3.tif
>
> Bingo! I wound up with a crisp PDF file whose size is only 48,071
> bytes: a 30-to-1 reduction. This size is typical of what I get
> when I do my own scanning. And by tweaking the threshold value
> from 0.82 to 0.9 I was able to bring out penciled notes without
> getting black blotches everywhere.
>
> Adding the capability to handle multi-page documents uncovered a
> few problems. The sizes of the images seem to vary from page to
> page, and some some pages have shadows that make it difficult to
> make pencil marks visible without getting those big black blotches
> I mentioned earlier. If I could persuade the person doing the
> scanning to be careful to avoid shadows, my final script should
> be able to do a wonderful job of cleaning up such files. This
> might not be an option, though - most people seem unable or
> unwilling to take the necessary care. At least the images
> aren't keystoned...
>
> Thanks, everyone, for your help!
Consider having a look at ImageMagick's convert with -lat, "local
adaptive thresholding". Sadly, my notes don't go beyond saying it's
better than just threshold... example command line:
convert in.pnm -lat 100x700-15% out.pbm
<https://usage.imagemagick.org/transform/#lat>
(unpaper might also be useful, depending on how the input documents
are?:)
<https://flameeyes.com/projects/unpaper>
(And if you end up converting the document to monochrome, it's probably
worth considering at least comparing with DjVu unless you need it to be
PDF.)
--
Nuno Silva
Back to comp.os.linux.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Shrinking huge PDF files Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2026-11-15 00:56 +0000
Re: Shrinking huge PDF files "Carlos E.R." <robin_listas@es.invalid> - 2026-11-15 02:16 +0100
Re: Shrinking huge PDF files Nuno Silva <nunojsilva@invalid.invalid> - 2026-11-15 10:40 +0000
Re: Shrinking huge PDF files "Carlos E.R." <robin_listas@es.invalid> - 2026-11-15 13:29 +0100
Re: Shrinking huge PDF files Nuno Silva <nunojsilva@invalid.invalid> - 2026-11-15 01:28 +0000
Re: Shrinking huge PDF files Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-11-15 01:49 +0000
Re: Shrinking huge PDF files 🇵🇱Jacek Marcin Jaworski🇵🇱 <jmj@energokod.gda.pl> - 2026-11-15 03:26 +0100
Re: Shrinking huge PDF files Rich <rich@example.invalid> - 2026-11-15 03:16 +0000
Re: Shrinking huge PDF files Andreas Eder <a_eder_muc@web.de> - 2026-11-15 10:50 +0100
Re: Shrinking huge PDF files Russell Marks <zgedneil@spam^H^H^H^Hgmail.com> - 2026-11-15 10:18 +0000
Re: Shrinking huge PDF files Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2026-11-15 23:31 +0000
Re: Shrinking huge PDF files c186282 <c186282@nnada.net> - 2026-11-15 22:16 -0500
Re: Shrinking huge PDF files Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2026-11-16 05:04 +0000
Re: Shrinking huge PDF files Mike Scott <usenet.16@scottsonline.org.uk.invalid> - 2026-11-16 07:09 +0000
Re: Shrinking huge PDF files Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2026-11-16 17:02 +0000
Re: Shrinking huge PDF files The Natural Philosopher <tnp@invalid.invalid> - 2026-11-16 18:17 +0000
Re: Shrinking huge PDF files Rich <rich@example.invalid> - 2026-11-16 18:55 +0000
Re: Shrinking huge PDF files c186282 <c186282@nnada.net> - 2026-11-16 21:29 -0500
Re: Shrinking huge PDF files Nuno Silva <nunojsilva@invalid.invalid> - 2026-11-22 11:00 +0000
Re: Shrinking huge PDF files "Carlos E.R." <robin_listas@es.invalid> - 2026-11-16 09:47 +0100
Re: Shrinking huge PDF files Nuno Silva <nunojsilva@invalid.invalid> - 2026-11-16 08:56 +0000
djvu [Was: Re: Shrinking huge PDF files] "Carlos E.R." <robin_listas@es.invalid> - 2026-11-16 11:15 +0100
Re: djvu [Was: Re: Shrinking huge PDF files] Andy Burns <usenet@andyburns.uk> - 2026-11-16 13:18 +0000
Re: djvu [Was: Re: Shrinking huge PDF files] Rich <rich@example.invalid> - 2026-11-16 19:00 +0000
Re: djvu [Was: Re: Shrinking huge PDF files] Nuno Silva <nunojsilva@invalid.invalid> - 2026-11-23 00:13 +0000
Re: djvu [Was: Re: Shrinking huge PDF files] "Carlos E.R." <robin_listas@es.invalid> - 2026-11-23 01:54 +0100
Re: djvu [Was: Re: Shrinking huge PDF files] Andy Burns <usenet@andyburns.uk> - 2026-11-23 06:35 +0000
Re: djvu [Was: Re: Shrinking huge PDF files] "Carlos E.R." <robin_listas@es.invalid> - 2026-11-17 03:00 +0100
Re: djvu [Was: Re: Shrinking huge PDF files] Rich <rich@example.invalid> - 2026-11-16 18:59 +0000
Re: Shrinking huge PDF files Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2026-11-16 17:02 +0000
Re: Shrinking huge PDF files Rich <rich@example.invalid> - 2026-11-16 19:01 +0000
Re: Shrinking huge PDF files Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2026-11-16 19:20 +0000
Re: Shrinking huge PDF files Leroy H <lh@somewhere.net> - 2026-11-16 20:03 +0000
Re: Shrinking huge PDF files Rich <rich@example.invalid> - 2026-11-16 22:04 +0000
Re: Shrinking huge PDF files Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2026-11-17 02:00 +0000
Re: Shrinking huge PDF files not@telling.you.invalid (Computer Nerd Kev) - 2026-11-17 07:25 +1000
csiph-web