pdf-color-to-gray

Howto convert pdf-files from color (RGB) to gray?

Summary:

gs -sProcessColorModel=DeviceGray -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=myfile-gray.pdf myfile.eps;

Here is a script that takes a (number of) pdf, or eps file(s) in RGB and creates new gray versions of the file(s).

# files to operate on. Source file may be EPS or PDF. FILES=$1

for i in $FILES; do

echo "operating on $i" # strip file suffix

j=`echo -n $i head -c -4`;

echo "filename before file suffix is $j" # If original is PDF, convert to eps to extract boundingbox

if file $i grep "PDF Document"; then

pdftops -eps $i $j.eps; i=$j.eps; echo "operating on $i" RM=$j.eps; fi # Store the boundingbox line BBox=`grep '%%BoundingBox:' $i`; echo "Storing $BBox for file $i"; # convert from RGB to gray gs -sProcessColorModel=DeviceGray -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=$j-gray.pdf $i; # convert to eps so we can insert the correct BoundingBox line again pdftops -eps $j-gray.pdf $i; # replace the current BoundingBox line with the one saved above sed "s/%%BoundingBox:.*/$BBox/" < $i >$j-gray.eps; # convert back to pdf again epstopdf —outfile=$j-gray.pdf $j-gray.eps; rm $RM $j-gray.eps done

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: oktober 17, 2019