Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created November 16, 2011 11:42
Show Gist options
  • Save JakubOboza/1369897 to your computer and use it in GitHub Desktop.
Save JakubOboza/1369897 to your computer and use it in GitHub Desktop.
ocnvert.sh
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: $0 url output-pdf-file"
exit 1
fi
set -e
documenturl="$(echo -n "$1" | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g')"
viewerurl="http://docs.google.com/viewer?url=$documenturl"
pdfurl="$(printf "$(curl -s "$viewerurl" | sed -n "s/.*gpUrl:'\\([^']*\\)'.*/\\1/p" | sed 's/%/%%/g')")"
cookiejar="$(mktemp)"
curl -s -L -c "$cookiejar" -o "$2" $pdfurl
rm -f "$cookiejar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment