Convert pdf to monochrome black-and-white via command line

Solution 1:

Adapting this answer over on SuperUser, this can be achieved by converting the PDF to PostScript and back using a redefined setrgbcolor command:

gs -o <output-file.pdf> -sDEVICE=pdfwrite \
-c "/osetrgbcolor {/setrgbcolor} bind def /setrgbcolor {pop [0 0 0] osetrgbcolor} def" \
-f <input-file.ps>

Solution 2:

This is what worked for me in Mint 20.04 to darken PDF text while trying to avoid the relatively heavy Adobe product.

To take a PDF with gray text and make it easier to read:

  1. Convert the PDF to individual image files:

    pdftoppm input_file.pdf output_file -png -rx 300 -ry 300
    

    where -rx 300 -ry 300 is the DPI.

  2. Export your PDF pages to image files, and then batch process them.

    Install XnConvert using its .deb package or using Flatpak. Add the PDF in the first tab. Go to AddMapBlack/White Points. White Points should be higher than Black Points. Put them at like 190 and 127 respectively (adjust from there).

    In the output tab use the following:

    • Filename: yourfilename
    • Format: PDF
    • Quality: 99
    • Multipage: Convert multipage file to multipage file.
  3. Install gscan2pdf and open the application. Drag and drop the selected batch of files from the file manager to the vertical bar on the left of the gscan2pdf app. FileSave, select Downsample to 150 PPI, select a name for your new PDF with blacker text.


I suspect the Adobe reader approach will work too, but here is a version without the Adobe product. On the upside, XnConvert seems quite flexible and lightweight. On the downside I don't think XnConvert is open source either.