🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Shrinking huge PDF files

#2628
From: c186282
Date: Mon, 16 Nov 2026 03:16
73 lines
4796 bytes
On 11/15/26 18:31, 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!


   Umm ... a two/three/four-stage CL 'solution' to
   what SHOULD be easy ?

   PDFs have a very useful place, but for SOME
   purposes they're an over-complex disaster.
Technical Details
Message-ID: <heednVhwn4gH6Gf3nZ2dnZfqnPSdnZ2d@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-3.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <Qq7KS.9052$s53.4981@fx10.iad> <%FfKS.6730$5s3.683@usenetxs.com> <NhrKS.21511$li3.13390@fx46.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-3.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 16 Nov 2026 03:16:42 +0000
Date: Sun, 15 Nov 2026 22:16:41 -0500
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> <%FfKS.6730$5s3.683@usenetxs.com>
 <NhrKS.21511$li3.13390@fx46.iad>
Content-Language: en-US
From: c186282 <c186282@nnada.net>
Organization: wokiesux
In-Reply-To: <NhrKS.21511$li3.13390@fx46.iad>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <heednVhwn4gH6Gf3nZ2dnZfqnPSdnZ2d@giganews.com>
Lines: 73
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-334riAgoSUlo1efoDSZWpw9GAvTECYIcVWB6wAPl7Ye2v92QEBAunn8EeRroZdvU/7Sm+4FpTDyOk2b!Ly/kTQFHDoiflY+0uDj6/lltt6GKoOUkHIcHwc0a7VqhT6aTUPJwwFMJ/eciHWJorRtW17LlAtA=
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