14

I have a pdf (having multiple pages) containing some colorful certificates, and need a black and white (grayscale) version of it.

Is there any way to make it grayscale with a single command, or with any simple GUI program (preferably FOSS)?

In principle, I can open all the pages separately in GIMP, make them grayscale, and rejoin, but that would take a lot of effort.

Archisman Panigrahi
  • 28,338
  • 18
  • 105
  • 212

4 Answers4

11

A similar question and answer is there in Stack Overflow.


Convert has the great disadvantage of converting to bitmap images, whatever you do... Try this out:

gs -sOutputFile=outfile.pdf -sDEVICE=pdfwrite \
  -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray \
  -dCompatibilityLevel=1.4 infile.pdf < /dev/null

You have to redirect from /dev/null because by default, gs is interactive. There is a host of options available to tune the output, you can look at the pdfwrite parameters of ghostscript.

In this method, the output pdf does not blow up in size, and also, its quality does not degrade.

Archisman Panigrahi
  • 28,338
  • 18
  • 105
  • 212
9

One of the ways is to use ImageMagick with some scripting.

You have to try its convert program as follows for single document:

convert -grayscale average color-in.pdf grayscale-out.pdf

More details about possible options are presented in its man-page locally by man convert or online.

Note: you may get "not authorized" message which is fixable by following this Q&A.

N0rbert
  • 99,918
  • 3
    +1 It works, but becomes blurry. I also tried -density 300. While it retains the quality, it turns a 1.4 MB PDF into 29 MB. Web services like https://pdfresizer.com/black-and-white can retain the size as well as the quality simultaneously. Something like this should be available in Ubuntu. – Archisman Panigrahi Dec 04 '21 at 21:39
  • With proper -density it gives nice grayscale. In case you need black/white with clean background it is more suitable -density 300 -threshold 75%. It may be useful when you keep original scans in color and want to reprint it. – x'ES Nov 07 '23 at 15:50
0

Download GIMP and open your pdf file. It will ask for resolution. There you can enter number pixels or select pixel/in etc. Now just went to Image >> Mode >> Grayscale. That is your complete pdf file is converted to grayscale. Now Go to File >> Export As >> yourfilename.pdf and press export. Edit: If you have problem getting large size file. You can opt for following options(In toto you have to achieve minimum number of colors to reduce your file size. If you understand that you get the solution.)

Step 1: Image >> Mode >> Grayscale

Step 2: Image >> Mode >> Indexed >> Generate optimum palette(Here you will find 256 numbers of colors) >> change the Maximum number of colors to 10 or any other value that suits your file size.

Step 3: If you want to reduce the file size further. Than you can opt for this step.

Image >> Mode >> Indexed >> Generate optimum palette >> Here this time select for Use web-optimized palette.

Note even if you want small size color pdf you can skip the step 1.

The reason for large size of pdf is number of colors.

Ajay
  • 678
  • Same issue as in N0rbert's answer. Either image quality is poor, or if a higher DPI is used, the PDF becomes huge. – Archisman Panigrahi Dec 06 '21 at 13:04
  • Trust me I am using it on daily basis. I opted for Gimp after trying many methods. Yes gs, convert and other are options. For large files convert consume huge memory. With gs and gv you have to you have to hit and try. I was not able to get that good quality. I am giving you other options by editing my answer. – Ajay Dec 06 '21 at 13:22
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