compress images in pdf files

30 06 2011

so this might be useful if you want to forward/store a pdf file (newsletter etc.) that contains uncompressed images. Using ghostscript you can resize them inside the pdf file.
$ pdfcompress inputfile.pdf outputfile.pdf

#!/bin/bash
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$2 $1
# more options:
# http://milan.kupcevic.net/ghostscript-ps-pdf/


With thanks to Milan Kupcevic for the inspiration. More options (especially regarding the image resolution) can be found on his page.

Advertisements




laser sword

22 06 2011

If you ever wanted to print colored text with a monochrome laser printer, you might have encountered the same problem I had: You just can’t read the light blue letters.
The following script can resolve the problem. It converts the pdf to a ps file and (as far as I understand) sets the font color to black (completeley black, not greyscale, halftonig etc.). The output file is a pdf again.
$ pdf_uncolor filename.pdf

#!/bin/bash
# adapted from http://superuser.com/questions/200378/converting-a-pdf-to-black-white-with-ghostscript
tempfile=/tmp/pdf_uncolor_temp.ps
rm $tempfile 
pdf2ps $1 $tempfile
gs -o bw_$1 -sDEVICE=pdfwrite -c "/setrgbcolor{0 mul 3 1 roll 0 mul 3 1 roll 0 mul 3 1 roll 0 mul add add setgray }def" -f $tempfile
rm $tempfile


Thanks to superuser.com for the template. Though I don’t completely understand the ps operations, I was able to adapt them to my needs.