#!/bin/sh - # $Id: webmgp2pdf,v 1.2 2004/02/17 22:27:53 sra Exp $ # # Hack to generate PDF files from a MagicPoint presentation that's # been posted on a web site. # # The basic idea here is to snarf the web version of a MagicPoint # presentation using wget, extract the screen images, then combine the # images into a PDF file. The resulting PDF is huge, because it's all # raster graphics, but it's easier to ship around than a directory # full of html and image files would be. # # This uses the NetPBM toolkit, and GhostScript. It's a kludge. Feel # free to do better, then send me what you did so I can use it too. # # Portions of this (eg, the anytopnm usage) really need rewriting. # # This program is hereby explictly placed in the public domain as # Beer-Ware. If we meet some day and you think this program is worth # it, you can buy me a beer. Your mileage may vary. We decline # responsibilities, all shapes, all sizes, all colors. If this # program breaks, you get to keep both pieces. # Filenames usage="usage: $0 url output.pdf" url="${1?"${usage}"}" output="${2?"${usage}"}" # No user servicable parts past this point. # Always mount a scratch monkey tmp="tmp.$$" trap "rm -rf '$tmp'" 0 1 2 3 13 15 mkdir "$tmp" # Snarf the files into our temp directory wget --mirror --relative --no-parent --no-directories --directory-prefix="$tmp" "$url" || { echo 1>&2 "$0: wget failed, giving up" exit 1 } # We now have a temporary directory containing PNG or JPG renderings # of our slides, along with a bunch of stuff we don't care about. # Find the image files find "$tmp" -type f \( -name 'mgp*.png' -o -name 'mgp*.jpg' \) ! -name '*.idx.*' >"$tmp/files" || { echo 1>&2 "$0: couldn't find images in downloaded presentation, giving up" exit 1 } # Extract and check the image geometry while read i; do bash anytopnm 2>/dev/null "$i" | pnmfile; done <"$tmp/files" | awk ' NR == 1 { x = $4; y = $6 } $4 != x || $6 != y { exit 1 } END { print x "0x" y "0" } ' >"$tmp/geometry" || { echo 1>&2 "$0: downloaded images weren't what i expected, giving up" exit 1 } # Convert the images to Postscript, then to PDF. It'd be nice to # include the thumbnails, but I don't know any easy way to do that. while read i ; do bash anytopnm "$i" | pnmtops -nocenter -noturn -dpi 72 -equalpixels; done <"$tmp/files" | ps2pdf13 "-g$(cat "$tmp/geometry")" - "$tmp/output.pdf" # That's it. mv -f "$tmp/output.pdf" "$output"