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


Swap File (Linux)

There is a way to use a file as swap space in Linux. This can be used if large swap space is needed temporarily. To enable this, follow the instructions on this page:

CentOS 5 document: Creating a Swap File

To disable (1st line) and remove (2nd line) the swapfile:

swapoff /path/to/swapfile
rm /path/to/swapfile