Created
December 8, 2014 12:38
-
-
Save cipri-tom/7d482b0f3c7df470691c to your computer and use it in GitHub Desktop.
Scaling PDFs with GhostScript under linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# modified from SO: http://stackoverflow.com/a/25932668/786559 | |
input=$2 | |
output=$(echo $2 | sed s/.pdf/_scaled.pdf/) | |
if [ $# -ne 2 ] ; then | |
echo "Bad arguments!" | |
exit | |
fi | |
# assume 0<=$1<=100 (no error checks!) | |
xx="595" #width of A4 in post script points | |
yy="842" #height of A4 in pps | |
ss=$(echo "scale=4; $1 / 2" | bc) | |
sx=$(echo "scale=4; ${xx}"'*'"( ${ss}/ 100 )" | bc) | |
sy=$(echo "scale=4; ${yy}"'*'"( ${ss}/ 100 )" | bc) | |
s=$(echo "scale=4; 1 - $1 / 100" | bc) | |
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \ | |
-dCompatibilityLevel="1.3" -dPDFSETTINGS="/screen" \ | |
-dSubsetFonts=true -dEmbedAllFonts=true \ | |
-sPAPERSIZE=a4 -sOutputFile="${output}" \ | |
-c "<</BeginPage{${s} ${s} scale ${sx} ${sy} translate}>> setpagedevice" \ | |
-f "$input" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment