Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate PDF from Publitas folder URL
#!/bin/sh
#
# Generates PDF from Publitas images (online folder service)
# Stores generated PDF and JSON (which may contains links).
#
# Requirements:
# - wget https://www.gnu.org/software/wget/
# - jq https://stedolan.github.io/jq/
# - imagemagick https://www.imagemagick.org/
#
# You may need to remove the PDF-related security policy for ImageMagick for this to work.
#
if [ ! "$2" ]; then
echo "Usage: $0 <publitas_folder_url> <output_name>"
exit 1
fi
URL="$1"
OUT="$2"
DIR=`mktemp -d --suffix=.getpublitas`
wget -q -O /dev/stdout "$URL" | sed 's/^\s*var\s\+data\s\+=\s\+\(.*\);\s*$/\1/p;d' > "$DIR/$NAME.json"
cat "$DIR/$NAME.json" | jq -r '.spreads[].pages[].images | .at2400 // .at2000 // .at1600 // .at1200 // .at1000' >"$DIR/img_urls"
i=1
for u in `cat "$DIR/img_urls"`; do
echo "$u" >"$DIR/cur_url" # use file to be able to use base
wget -q --base="$URL" -O `printf "$DIR/image-page-%04d.jpg" $i` -i "$DIR/cur_url"
i=$(( $i + 1 ))
done
convert "$DIR/image-page-*.jpg" "$OUT.pdf"
cp "$DIR/$NAME.json" "$OUT.json"
rm -Rf "$DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.