Skip to content

Instantly share code, notes, and snippets.

@wvengen
Created October 11, 2018 09:10
Show Gist options
  • Save wvengen/27162f92acadfaf3ac6b782b9a018285 to your computer and use it in GitHub Desktop.
Save wvengen/27162f92acadfaf3ac6b782b9a018285 to your computer and use it in GitHub Desktop.
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"
@crfigo-dentsu
Copy link

Hi @Cristark02, As far as I know it still works. Make sure that you add the /unsupported to the end of the "root" url like this: https://view.publitas.com/four-hands/fourhands_fall23/page/1https://view.publitas.com/four-hands/fourhands_fall23/unsupported

I logged in just to say I'd kiss you if I had you in front of me.
Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment