Mika's Site

Convert PDF to grayscale using Ghostscript

This is a Bash function I have in my .bashrc. This function uses Ghostscript (gs), which must be installed in the system.

# Convert pdf to grayscale
function pdf2gray {
    gs \
    -sDEVICE=pdfwrite \
    -sProcessColorModel=DeviceGray \
    -sColorConversionStrategy=Gray \
    -dOverrideICC \
    -f $1 \
    -o $2
}

In this example a file called abc.pdf is converted to grayscale copy called abc_gray.pdf. The first argument is the input file and the second argument is the output file. Note: My function doesn’t check if these are given or not.

pdf2gray abc.pdf abc_gray.pdf