After exhausting the usual suspects (Adobe Acrobat, ImageMagick, Ghostscript, etc.), stumbled onto the cleanest results and smallest file size by pairing Preview.app and IrfanView:
Substituting convert and gs for steps 3 and 4 led to cleaner output in some cases, albeit at the expense of larger file sizes:
$convert bw.tif bw2.pdf
$gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=bw3.pdf bw2.pdf
Resolved this error:
convert-im6.q16: cache resources exhausted `bw.tif' @ error/cache.c/OpenPixelCache/4095. convert-im6.q16: no images defined `bw2.pdf' @ error/convert.c/ConvertImageCommand/3229.
by increasing the values for memory and disk in /etc/ImageMagick-6/policy.xml from these defaults to several GiBs each:
<policy domain="resource" name="memory" value="256MiB"/> <policy domain="resource" name="disk" value="1GiB"/>
The gs options used:
-sDEVICE=pdfwrite
: Tells Ghostscript to output a PDF.-dCompatibilityLevel=1.4
: Sets the compatibility level of the output PDF.-dPDFSETTINGS=/ebook
: This setting balances quality and file size; use /screen
for lower quality and smaller file size, or /prepress
for higher quality at the expense of larger file size.-dNOPAUSE -dQUIET -dBATCH
: These options run Ghostscript in batch mode without pausing between pages.-sOutputFile=bw3.pdf
: Specifies the name of the output file.bw2.pdf
: The input PDF file./misc | Apr 15, 2021