SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2010-11-25 17:57:56

GuruX
#! Die Hard
Registered: 2009-01-18
Posts: 527

Shrinkpdf

Quite often, I need to shrink pdf's to make them a suitable file size for mailing. I prefer to never mail files larger than 1 mb. So I found this neat little script on the net. It's basically a CLI script that prompts for resolution and output filename.

I found it at http://www.tatome.de/bliki/doku.php?id= … :shrinkpdf

#!/bin/bash
 
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
    echo usage: shrinkpdf \<filename\> \<resolution\> \[\<output\>\]
    exit
fi
 
if [ ! -e "$1" ]; then
    echo "$1" does not exist. Exiting.
    exit
fi
 
if [ $# = 3 ]; then
    NEWNAME=$3
else
    NEWNAME=`basename $1 .pdf`_shrinked.pdf
fi
 
if [ "$1 " = "$NEWNAME " ]; then
    echo Input and output are identical. Won\'t overwrite---exiting.
    exit
fi
 
if [ -e "$NEWNAME" ]; then
    echo "$NEWNAME" exists. Delete? \(y/n\)
    read ANS
    if [ "$ANS " = "y " ]; then
        rm "$NEWNAME"
    else
        exit
    fi
fi
 
gs    -q -dNOPAUSE -dBATCH -dSAFER \
    -sDEVICE=pdfwrite \
    -dCompatibilityLevel=1.3 \
    -dPDFSETTINGS=/screen \
    -dEmbedAllFonts=true \
    -dSubsetFonts=true \
    -dColorImageDownsampleType=/Bicubic \
    -dColorImageResolution=$2 \
    -dGrayImageDownsampleType=/Bicubic \
    -dGrayImageResolution=$2 \
    -dMonoImageDownsampleType=/Bicubic \
    -dMonoImageResolution=$2 \
    -sOutputFile="$NEWNAME" \
     "$1"
 
echo $1: $((`wc -c "$1" | cut -d \  -f 1` / 1024 )) kb
echo $NEWNAME: $((`wc -c "$NEWNAME" | cut -d \  -f 1` / 1024 )) kb

Just paste it into a new file, name it shrinkpdf.sh make it executable, usage is: shrinkpdf <filename> <resolution> [<output>]

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo