Skip to content

Instantly share code, notes, and snippets.

@rsnemmen
Created November 4, 2014 17:07
Show Gist options
  • Save rsnemmen/76d1ce067aaa2e306ec4 to your computer and use it in GitHub Desktop.
Save rsnemmen/76d1ce067aaa2e306ec4 to your computer and use it in GitHub Desktop.
Perl script to convert a color PDF to grayscale
#!/usr/bin/perl -w
#
# Source: http://handyfloss.net/2008.09/making-a-pdf-grayscale-with-ghostscript/
# handyfloss blog
#
# Usage: pdf2gray.pl input_color.pdf
use strict;
my $infile = $ARGV[0];
my $outfile = $infile;
$outfile =~ s/\.pdf$//;
$outfile = $outfile."_gray.pdf";
system "gs -sOutputFile=$outfile -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH $infile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment