Using ImageMagick convert utility #
Convert program throws an error, unless you change security policy by adding this line to /etc/ImageMagick-6/policy.xml
<policy domain="coder" rights="read | write" pattern="PDF" />
Threshold percentage #
Lower value allows more noise from non-white pixels, higher is more restrictive. Example:
convert -density 300 -threshold 70% 'rj my_input.pdf my_output.pdf
Alternative: Ghostscript #
I got it working for converting color to greyscale, but not for conversion to black and white. Example:
gs -sOutputFile=output.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH 'input.pdf'
Alternative: pdfcpu #
Works with image files but not PDF or PS streams. Example:
pdfcpu import -- "gray:true" 'input.pdf' 'output.pdf'
Results in error:
input.pdf needs an image extension (.jpg, .jpeg, .png, .tif, .tiff, .webp)