Skip to content

Commit

Permalink
Bug workaround for getSize of PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
Egil Moeller committed May 10, 2011
1 parent 0d7742e commit cac74c0
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion etherpad/src/plugins/imageConvert/getSize.sh
Expand Up @@ -5,7 +5,39 @@ page="$2"
mime="$(file -L -b -i "$filename" | sed -e "s+;.*++g")"

if [ "$mime" == "application/pdf" ]; then
pdfinfo -f $page -l $page "$filename" | grep "Page.*size:" | sed -e "s+Page.*size: *\([0-9.]*\) x \([0-9.]*\) .*+\1\n\2+g"
orderToOrientation () {
read width
read height
if ((height > width)); then
echo "portrait";
else
echo "landscape";
fi
}

getPageOrientation () {
{
tmp="$(mktemp)"
pdftoppm -png -f 1 -l 1 -scale-to 200 "$1" "$tmp"
identify -format "%[fx:w]\n%[fx:h]" "$tmp"*.png
rm "$tmp"*
} | orderToOrientation
}

SHOULD_BE_ORIENTATION="$(getPageOrientation "$filename")"

pdfinfo -f $page -l $page "$filename" | grep "Page.*size:" | sed -e "s+Page.*size: *\([0-9.]*\) x \([0-9.]*\) .*+\1\n\2+g" | {
read width
read height

IS_ORIENTATION="$({ echo "$width"; echo "$height"; } | orderToOrientation)"

if [ "$SHOULD_BE_ORIENTATION" == "$IS_ORIENTATION" ]; then
echo "$width"; echo "$height";
else
echo "$height"; echo "$width";
fi
}
else
identify -format "%[fx:w]\n%[fx:h]" "$filename[$page]"
fi

0 comments on commit cac74c0

Please sign in to comment.