• Shrinking huge PDF files

    From Charlie Gibbs@cgibbs@kltpzyxm.invalid to comp.os.linux.misc on Sun Nov 15 00:56:16 2026
    From Newsgroup: comp.os.linux.misc

    [Here's an on-charter post for a change...]

    I was given some scans of sheet music from an iPad vict^H^H^H^Huser who couldn't find the settings (if it has any) for its scanning function.
    As a result, she wound up with a 9-page PDF file that takes up over
    30 megabytes. (When I scan a similar document on my machine the file
    is about one megabyte.) A bit of digging came up with utilities that
    tell me that her scan is in 24-bit colour at some ungodly resolution
    (using JPEG to keep it from being even bigger).

    I've been looking at utilities like Ghostscript, but the documentation
    is making my eyes glaze over. Is there a guide that can help me
    re-sample the file, say to 300 dpi in monochrome?

    I suppose the alternative would be to have the user find someone
    who could help her beat macOS into submission, but that might
    wind up more like that episode of "The Big Bang Theory":

    Leonard: Oh, screw the roommate agreement.
    Sheldon: No! You don't screw the roommate agreement.
    The roommate agreement screws _you_!

    aTdHvAaNnKcSe...
    --
    /~\ Charlie Gibbs | In this world there are
    \ / <cgibbs@kltpzyxm.invalid> | two kinds of people:
    X I'm really at ac.dekanfrus | 1. Those who can extrapolate
    / \ if you read it the right way. | from incomplete data.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Carlos E.R.@robin_listas@es.invalid to comp.os.linux.misc on Sun Nov 15 02:16:01 2026
    From Newsgroup: comp.os.linux.misc

    On 2026-11-15 01:56, Charlie Gibbs wrote:
    [Here's an on-charter post for a change...]

    I was given some scans of sheet music from an iPad vict^H^H^H^Huser who couldn't find the settings (if it has any) for its scanning function.
    As a result, she wound up with a 9-page PDF file that takes up over
    30 megabytes. (When I scan a similar document on my machine the file
    is about one megabyte.) A bit of digging came up with utilities that
    tell me that her scan is in 24-bit colour at some ungodly resolution
    (using JPEG to keep it from being even bigger).

    I've been looking at utilities like Ghostscript, but the documentation
    is making my eyes glaze over. Is there a guide that can help me
    re-sample the file, say to 300 dpi in monochrome?

    Convert to some bitmap image format, file per page (png, for instance)
    resample using gimp, or magick
    convert back to PDF, if that is the goal.


    Hint: don't fight documentation. Ask an AI to guide you on the use of ghostscript (if that is the tool you want to use). AIs are good at this.

    (no, I did not ask an AI for this post)
    --
    Cheers, Carlos.
    ESEfc-Efc+, EUEfc-Efc|;
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Nuno Silva@nunojsilva@invalid.invalid to comp.os.linux.misc on Sun Nov 15 01:28:23 2026
    From Newsgroup: comp.os.linux.misc

    On 2026-11-15, Charlie Gibbs wrote:

    [Here's an on-charter post for a change...]

    I was given some scans of sheet music from an iPad vict^H^H^H^Huser who couldn't find the settings (if it has any) for its scanning function.
    As a result, she wound up with a 9-page PDF file that takes up over
    30 megabytes. (When I scan a similar document on my machine the file
    is about one megabyte.) A bit of digging came up with utilities that
    tell me that her scan is in 24-bit colour at some ungodly resolution
    (using JPEG to keep it from being even bigger).

    I've been looking at utilities like Ghostscript, but the documentation
    is making my eyes glaze over. Is there a guide that can help me
    re-sample the file, say to 300 dpi in monochrome?

    I suppose the alternative would be to have the user find someone
    who could help her beat macOS into submission, but that might
    wind up more like that episode of "The Big Bang Theory":

    Leonard: Oh, screw the roommate agreement.
    Sheldon: No! You don't screw the roommate agreement.
    The roommate agreement screws _you_!

    aTdHvAaNnKcSe...

    If the pages are regular images in the PDF (and not e.g. some composite
    image using some technique to achieve separate layers using different
    images in the same page), I'd extract them with pdfimages (from
    libpoppler, probably with the -all option (-j has served me well in the
    past, but I should have chosen -all?)), convert to a different
    colorspace using imagemagick or equivalent, and then either re-assemble
    these in a PDF file or create a ZIP file with the extension .CBZ (in
    case that increases the chances of document viewers handling it as a
    collection of pages in a ZIP archive).

    (Actually, I'd probably first see if they could convert to monochrome
    well, playing with the threshold in imagemagick's convert, and if so I'd instead use cjb2 and djvm to turn the whole thing into a DjVu file.)

    But IIRC Ghostscript does indeed have something for resolution and
    colorspace, let me see if I have something written down... yes, part of
    a command I wrote down has:

    gs -sDEVICE=pdfwrite -sColorConversionStrategy=Gray \
    -sProcessColorModel=DeviceGray

    But I have no idea if this actually worked or if it was just something I
    wrote down while trying to make it work.


    From a web search, I guess this is the web version of the current
    manual?:
    <https://ghostscript.readthedocs.io/en/latest/VectorDevices.html>

    (Also see {Color,Gray,Mono}ImageResolution, which are listed there but
    are not documented at least on this section?)
    --
    Nuno Silva
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.os.linux.misc on Sun Nov 15 01:49:47 2026
    From Newsgroup: comp.os.linux.misc

    On Sun, 15 Nov 2026 00:56:16 GMT, Charlie Gibbs wrote:

    I've been looking at utilities like Ghostscript, but the
    documentation is making my eyes glaze over.

    According to the docs <https://ghostscript.readthedocs.io/en/gs10.08.0/Devices.html>, the rCLpngmonorCY and rCLpngmonodrCY output devices should give you 1 bit per pixel, with the latter doing error-diffusion dithering. Or have a look
    at some of the other device options there.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?B?8J+HtfCfh7FKYWNlayBNYXJjaW4gSmF3b3Jza2nwn4e18J+HsQ==?=@jmj@energokod.gda.pl to comp.os.linux.misc on Sun Nov 15 03:26:30 2026
    From Newsgroup: comp.os.linux.misc

    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+eych
    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 *+Uwiat 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 Efc|Efc#, UE Efc-Efc|;
    Pryw. s. WWW: <https://energokod.gda.pl>; Pryw. tel.: +48-609-170-742; Netykieta: <https://energokod.gda.pl/Netykieta.html>.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.os.linux.misc on Sun Nov 15 03:16:46 2026
    From Newsgroup: comp.os.linux.misc

    Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:
    [Here's an on-charter post for a change...]

    I was given some scans of sheet music from an iPad vict^H^H^H^Huser who couldn't find the settings (if it has any) for its scanning function.
    As a result, she wound up with a 9-page PDF file that takes up over
    30 megabytes. (When I scan a similar document on my machine the file
    is about one megabyte.) A bit of digging came up with utilities that
    tell me that her scan is in 24-bit colour at some ungodly resolution
    (using JPEG to keep it from being even bigger).

    I've been looking at utilities like Ghostscript, but the documentation
    is making my eyes glaze over. Is there a guide that can help me
    re-sample the file, say to 300 dpi in monochrome?

    If it really is a "scan" (as in an image of a sheet of paper) and if
    you are fine with it becoming monochrome, then you can do this:

    $ gs -dNOPAUSE -q -r300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=page%02d.tiff big-monster.pdf

    This will give you a set of tiffg4 monochrome images, one for each
    page, at 300dpi.

    Then, you can reassemble a pdf by using 'tiff2pdf' from the libtiff
    package like so:

    $ tiffcp page*.tiff multi-page.tiff
    $ tiff2pdf -o new-smaller-file.pdf multi-page.tiff


    Note, if it is a 24bit scan, and the black's are not really black but
    instead a dark grey, then the above will create a dithered output that
    will look awful and will not G4 compress well at all.

    In which case, you have extra work to do (and you also need the netpbm utilities). First, convert to grey scale:

    $ gs -dNOPAUSE -q -r300 -sDEVICE=pgmraw -dBATCH -sOutputFile=page%02d.pgm big-monster.pdf

    Then threshold the grey scale to black, and convert back to G4 tiffs:

    $ for page in page*.pgm ; do pgmtopbm -threshold -value 0.82 $page | pnmtotiff -g4 > ${page%.pgm}.tiff ; done

    Set each tiff to say it is 300dpi

    $ for page in page*.tiff ; do tiffset -s 296 2 $page ; tiffset -s 282 300 $page ; tiffset -s 283 300 $page ; done

    Create a multipage tiff from the individual single page tiffs and then
    create a pdf from the multi-page tiff:

    $ tiffcp page*.tiff multi-page.tiff
    $ tiff2pdf -o new-smaller-file.pdf multi-page.tiff

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Andreas Eder@a_eder_muc@web.de to comp.os.linux.misc on Sun Nov 15 10:50:43 2026
    From Newsgroup: comp.os.linux.misc

    On So 15 Nov 2026 at 00:56, Charlie Gibbs wrote:

    [Here's an on-charter post for a change...]

    I was given some scans of sheet music from an iPad vict^H^H^H^Huser who couldn't find the settings (if it has any) for its scanning function.
    As a result, she wound up with a 9-page PDF file that takes up over
    30 megabytes. (When I scan a similar document on my machine the file
    is about one megabyte.) A bit of digging came up with utilities that
    tell me that her scan is in 24-bit colour at some ungodly resolution
    (using JPEG to keep it from being even bigger).

    I've been looking at utilities like Ghostscript, but the documentation
    is making my eyes glaze over. Is there a guide that can help me
    re-sample the file, say to 300 dpi in monochrome?

    What I do ro make pdfs smaller is the following:

    # $1=input, $2=output
    gs -q -dNOPAUSE -dBATCH \
    -sDEVICE=pdfwrite \
    -sOutputFile="$2" \
    -r1200 \
    -dAutoRotatePages=/None \
    -dCompressFonts=true \
    -dDetectDuplicateImages \
    -dEmbedAllFonts \
    -dPDFSETTINGS=/prepress \
    -dPrinted=false \
    $zdistill $zres \
    -f "$1"
    #
    # -r1200 is to avoid rendering on a tiny canvas, which can trip
    # heuristics of complicated fonts, as (relating to a Hans font) in:
    # https://bugs.ghostscript.com/show_bug.cgi?id=701753
    # -dAutoRotatePages since no, we do not want pages randomly rotated.
    # -dCompressFonts seems not to hurt, and can save notable space.
    # -dDetectDuplicateImages similarly.
    # -dEmbedAllFonts usually but doesn't always work to embed fonts,
    # except that if downscaling images with zres, have to override.
    # -dPDFSETTINGS=/prepress needed for embedding with
    # 45-2/watters-litigator/doc.pdf (tb140)
    # -dPrinted=false is to preserve internal links within the pdf,
    # notably for the cover/cover3 in our tb*complete.pdf:
    # https://tex.stackexchange.com/questions/456896

    For grayscale output, can add
    -sColorConversionStrategy=Gray \
    -dProcessColorModel=/DeviceGray \

    You can find full notes (e.g., options no longer used) and runnable scripts: https://github.com/TeXUsersGroup/tugboat/blob/trunk/misc/ps2pdf-tub https://github.com/TeXUsersGroup/tugboat/blob/trunk/misc/ps2pdf-gray-tub

    Hope this helps,

    'Andreas
    --
    ceterum censeo redmondinem esse delendam
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Russell Marks@zgedneil@spam^H^H^H^Hgmail.com to comp.os.linux.misc on Sun Nov 15 10:18:35 2026
    From Newsgroup: comp.os.linux.misc

    Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:

    I was given some scans of sheet music from an iPad vict^H^H^H^Huser who couldn't find the settings (if it has any) for its scanning function.
    As a result, she wound up with a 9-page PDF file that takes up over
    30 megabytes. (When I scan a similar document on my machine the file
    is about one megabyte.) A bit of digging came up with utilities that
    tell me that her scan is in 24-bit colour at some ungodly resolution
    (using JPEG to keep it from being even bigger).

    I've been looking at utilities like Ghostscript, but the documentation
    is making my eyes glaze over. Is there a guide that can help me
    re-sample the file, say to 300 dpi in monochrome?

    I'm not sure about that, but here's one thing I ended up using
    recently to get smaller PDFs (possibly including some unnecessary
    options):

    gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen \
    -dNOPAUSE -dBATCH -sOutputFile=out.pdf in.pdf

    It won't always make the file smaller, but did for me in some cases.
    That does a reduction to 72 DPI, but I think you can replace "/screen"
    with "/printer" to get 300.

    -Rus.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Nuno Silva@nunojsilva@invalid.invalid to comp.os.linux.misc on Sun Nov 15 10:40:38 2026
    From Newsgroup: comp.os.linux.misc

    On 2026-11-15, Carlos E.R. wrote:

    On 2026-11-15 01:56, Charlie Gibbs wrote:
    [Here's an on-charter post for a change...]

    I was given some scans of sheet music from an iPad vict^H^H^H^Huser who
    couldn't find the settings (if it has any) for its scanning function.
    As a result, she wound up with a 9-page PDF file that takes up over
    30 megabytes. (When I scan a similar document on my machine the file
    is about one megabyte.) A bit of digging came up with utilities that
    tell me that her scan is in 24-bit colour at some ungodly resolution
    (using JPEG to keep it from being even bigger).

    I've been looking at utilities like Ghostscript, but the documentation
    is making my eyes glaze over. Is there a guide that can help me
    re-sample the file, say to 300 dpi in monochrome?

    Convert to some bitmap image format, file per page (png, for instance) resample using gimp, or magick

    For this I stress my recommendation of poppler's pdfimages. If I'm not mistaken, it will extract the image streams, not convert them. If all it
    has is one image per page, that's probably the best to avoid loss at
    this stage.

    (Well, if you do indeed convert to raster here, instead of extracting,
    you can probably use this step to convert the colorspace and (if needed) downsample the images.)

    convert back to PDF, if that is the goal.


    Hint: don't fight documentation. Ask an AI to guide you on the use of ghostscript (if that is the tool you want to use). AIs are good at
    this.

    (no, I did not ask an AI for this post)
    --
    Nuno Silva
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Carlos E.R.@robin_listas@es.invalid to comp.os.linux.misc on Sun Nov 15 13:29:25 2026
    From Newsgroup: comp.os.linux.misc

    On 2026-11-15 11:40, Nuno Silva wrote:
    On 2026-11-15, Carlos E.R. wrote:

    On 2026-11-15 01:56, Charlie Gibbs wrote:
    [Here's an on-charter post for a change...]

    I was given some scans of sheet music from an iPad vict^H^H^H^Huser who
    couldn't find the settings (if it has any) for its scanning function.
    As a result, she wound up with a 9-page PDF file that takes up over
    30 megabytes. (When I scan a similar document on my machine the file
    is about one megabyte.) A bit of digging came up with utilities that
    tell me that her scan is in 24-bit colour at some ungodly resolution
    (using JPEG to keep it from being even bigger).

    I've been looking at utilities like Ghostscript, but the documentation
    is making my eyes glaze over. Is there a guide that can help me
    re-sample the file, say to 300 dpi in monochrome?

    Convert to some bitmap image format, file per page (png, for instance)
    resample using gimp, or magick

    For this I stress my recommendation of poppler's pdfimages. If I'm not mistaken, it will extract the image streams, not convert them. If all it
    has is one image per page, that's probably the best to avoid loss at
    this stage.

    Ok, yes. Although I used convert loosely, what I wanted to do is extract
    the original image inside.
    --
    Cheers, Carlos.
    ESEfc-Efc+, EUEfc-Efc|;
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Charlie Gibbs@cgibbs@kltpzyxm.invalid to comp.os.linux.misc on Sun Nov 15 23:31:57 2026
    From Newsgroup: comp.os.linux.misc

    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!
    --
    /~\ Charlie Gibbs | Life is perverse.
    \ / <cgibbs@kltpzyxm.invalid> | It can be beautiful -
    X I'm really at ac.dekanfrus | but it won't.
    / \ if you read it the right way. | -- Lily Tomlin
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From c186282@c186282@nnada.net to comp.os.linux.misc on Sun Nov 15 22:16:41 2026
    From Newsgroup: comp.os.linux.misc

    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.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Charlie Gibbs@cgibbs@kltpzyxm.invalid to comp.os.linux.misc on Mon Nov 16 05:04:00 2026
    From Newsgroup: comp.os.linux.misc

    On 2026-11-16, c186282 <c186282@nnada.net> wrote:

    On 11/15/26 18:31, Charlie Gibbs wrote:

    Thanks, everyone, for your suggestions. Here's a history of my
    various attempts.

    <snipped>

    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.

    Perhaps, but non-experts are used to them and they're an
    easy way to transmit images. And what I'm trying to do
    is not easy; I've been handed a PDF file scanned at 2400
    dpi in 24-bit colour, which I want to transform into a
    monochrome file at 600 dpi. The 30-to-1 size advantage
    turns a file transfer that requires Google Drive or Dropbox
    into a simple e-mail attachment that displays quickly and
    is more readable.

    Yes, the ultimate solution would to have the person scanning
    the file set up appropriate settings. But if that person
    doesn't know the fine points of scanning and is at the mercy
    of Apple (or Microsoft or whoever), this might not be an option.
    --
    /~\ Charlie Gibbs | In this world there are
    \ / <cgibbs@kltpzyxm.invalid> | two kinds of people:
    X I'm really at ac.dekanfrus | 1. Those who can extrapolate
    / \ if you read it the right way. | from incomplete data.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Mike Scott@usenet.16@scottsonline.org.uk.invalid to comp.os.linux.misc on Mon Nov 16 07:09:49 2026
    From Newsgroup: comp.os.linux.misc

    On 16/11/2026 05:04, Charlie Gibbs wrote:
    On 2026-11-16, c186282 <c186282@nnada.net> wrote:

    On 11/15/26 18:31, Charlie Gibbs wrote:

    Thanks, everyone, for your suggestions. Here's a history of my
    various attempts.

    <snipped>

    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.

    Perhaps, but non-experts are used to them and they're an
    easy way to transmit images. And what I'm trying to do
    is not easy; I've been handed a PDF file scanned at 2400
    dpi in 24-bit colour, which I want to transform into a
    monochrome file at 600 dpi. The 30-to-1 size advantage
    turns a file transfer that requires Google Drive or Dropbox
    into a simple e-mail attachment that displays quickly and
    is more readable.

    GIMP might possibly help? Off the top of my head, import your pdf with
    pages as layers, fiddle with colour, size and resolution, then export
    layers as pages in a pdf.


    Yes, the ultimate solution would to have the person scanning
    the file set up appropriate settings. But if that person
    doesn't know the fine points of scanning and is at the mercy
    of Apple (or Microsoft or whoever), this might not be an option.

    --
    Mike Scott
    Harlow, England
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Carlos E.R.@robin_listas@es.invalid to comp.os.linux.misc on Mon Nov 16 09:47:35 2026
    From Newsgroup: comp.os.linux.misc

    On 2026-11-16 00:31, Charlie Gibbs wrote:
    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...

    You can script conversion to grayscale instead. And you can downsample, too.
    --
    Cheers, Carlos.
    ESEfc-Efc+, EUEfc-Efc|;
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Nuno Silva@nunojsilva@invalid.invalid to comp.os.linux.misc on Mon Nov 16 08:56:28 2026
    From Newsgroup: comp.os.linux.misc

    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
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Carlos E.R.@robin_listas@es.invalid to comp.os.linux.misc on Mon Nov 16 11:15:48 2026
    From Newsgroup: comp.os.linux.misc

    On 2026-11-16 09:56, Nuno Silva wrote:
    (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.)

    How do you handle conversion to djvu in Linux? I have found few people that use this format.

    I use a script, that basically does this:

    C44=c44
    PNGTOPNM=pngtopnm


    "image/jpeg") $C44 -dpi 240 -slice $SLICE -crcbhalf "$FILE"

    "image/png")

    $PNGTOPNM "$FILE" > "$NOMBRECMPLTO"pnm
    $C44 -dpi $DPI -slice "23+19+17+13+9+7+5+3" -crcbhalf "$NOMBRECMPLTO"pnm
    rm "$NOMBRECMPLTO"pnm


    (I do some adjustments depending on DPI, but I removed for clarity)


    I understand that there are better tools (payware) in Windows.
    --
    Cheers, Carlos.
    ESEfc-Efc+, EUEfc-Efc|;
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Andy Burns@usenet@andyburns.uk to comp.os.linux.misc on Mon Nov 16 13:18:46 2026
    From Newsgroup: comp.os.linux.misc

    "Carlos E.R." wrote:

    How do you handle conversion to djvu in Linux? I have found few people
    that use this format.

    I can see that at one time, DjVu would have had advantages over Pdf, is
    that still true, especially with Pdf/A ?

    --- Synchronet 3.22a-Linux NewsLink 1.2