15

I have a 65-page PDF file that has text in a dark grey. (Actual text, not a picture/image of text.) Printing on my B/W printer, the text gets all blurry, because the printer is trying to make it less than black. I can solve this problem page-per-page by importing the pages to inkscape, selecting all paths, clicking on "Black", which converts all colours including the greytones to pure black, and exporting back to PDF.

Is there a way to do these steps in inkscape in the command line (for batch processing)?

Is there a way to achieve the same result (convert pdf to black and white, 1-bit greyscale) without inkscape?


Edit. There are similar questions on Unix.SE and on superuser, which use Ghostscript. However, these only convert the files to greyscale via the option -sColorConversionStrategy=Gray. The option -sColorConversionStrategy=/Mono results in the error Unrecoverable error: rangecheck in .putdeviceprops. Since my file is greyscale already, these don't solve my problem.

Earthliŋ
  • 621
  • 2
  • 11
  • 29

7 Answers7

12

This answer given at superuser worked for me, I did not get other answers on this question working within 2 minutes. Credits go to goyinux for the original answer.

gs \
 -sOutputFile=output.pdf \
 -sDEVICE=pdfwrite \
 -sColorConversionStrategy=Gray \
 -dProcessColorModel=/DeviceGray \
 -dCompatibilityLevel=1.4 \
 -dNOPAUSE \
 -dBATCH \
 input.pdf

---EDIT---

This answer does not answer the question. (The solution is not monochrome(~=1 color), but black and white(can be multiple grayscales), as pointed out in the comment by milahu).

I came here through a search query on black and white and did not understand "monochrome" and ignored it. Based on the votes, it looks like more people end up here for "black and white" instead of "monochrome black and white". My apologies for polluting the question.

a.t.
  • 387
5

This has worked for GhostScript 10, which has apparently added suport for blackening the vectors in 2022:

gs \
 -sOutputFile=output.pdf \
 -sDEVICE=pdfwrite \
 -dBlackText -dBlackVector \
 -dNOPAUSE -dBATCH \
 input.pdf
che
  • 243
1

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.

b n
  • 11
1
convert -colorspace GRAY color.pdf gray.pdf
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>
Earthliŋ
  • 621
  • 2
  • 11
  • 29
0

I have written a shell script to convert any pdf to monochrome i.e. to pure black and white. Please check it out and let me know if you face any problem.

Deva
  • 21
  • 1
0

In my case I am keeping signed document scans in color, but need reprint it without gray noice. For this case works well

convert -density 300 -threshold 75% input.pdf output.pdf

(based on the answer)

Range between 50%-75% works fine in circumstances when you have color scan PDF (text as image) with original resolution 300dpi.

In case of text saved as PDF (not image) you will get huge increasing of output file size.

x'ES
  • 101
  • 1