8

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.

6
  • 1
    Would it necessarily have to be an inkscape command or are other PDF conversion tools also okay? (I don't know how to do it, I'm just trying to improve the question)
    – Byte Commander
    Jan 31 '16 at 13:35
  • @ByteCommander Other PDF conversion tools would be okay as well.
    – Earthliŋ
    Jan 31 '16 at 13:42
  • Your pdf file, is it textual or image (i.o.w. is the text selectable or not)? Jan 31 '16 at 20:39
  • @JacobVlijm It's text, not an image. (It contains a couple of figures, which I don't need to convert to B/W. I care primarily about the readability of the text.)
    – Earthliŋ
    Jan 31 '16 at 21:09
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>
5
  • Does not work with gs 9.26. The document remains in colour. Mar 6 at 19:39
  • @XavierStuvw Still works for me with gs 9.50 on embedded text, vector graphics and images. Did you use a PostScript file as input? How are you checking the output?
    – Earthliŋ
    Mar 6 at 19:52
  • Yes, I used a ps as input; would you please add the line that converts the original pdf into a ps for good measure? What do you mean for 'checking the output'? NB My document is scanned book, and each page appears to be an image. Mar 6 at 19:56
  • I just use the "Print to File" option in the "Print" dialog, selecting PS as filetype. I don't know what command this uses under the hood, but I get similar results with pdf2ps which seems to use GhostScript and it doesn't work with PS files generated by pdftops which uses Poppler (leaving colours as they are). The reason I was asking how you check is that I used to use Evince for checking if the conversion from a dark grey to true black worked, but some versions of Evince used to display true black #000000 in PDF files as something like #111111 (presumably to be "screen-friendly").
    – Earthliŋ
    Mar 6 at 20:13
  • If pdf2ps works also for you, I'll add this to my answer, but a scanned book should probably be converted to greyscale rather than pure B/W using something like this answer on superuser...? @XavierStuvw
    – Earthliŋ
    Mar 6 at 20:16
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.

0

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.

0

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
-1
convert -colorspace GRAY color.pdf gray.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.