#! /usr/local/bin/bash # # Create a J2ME Midlet from a PostScript or PDF source suitable to read on # a java enabled phone # # 8-Sep-2009 S.Menke # # usage () { cat < Usage: $0 [options] [] [] [...] reads the .ps or .pdf file , renders the pages in sizes (they are assumed to be in increasing order), and writes output to .ja{r,d} Options: -h print this help and exit -f first page to process -l last page to process -z first zoom level to start tiling of images (default=1) Example: $0 talk.pdf MyTalk 14 56 will create MyTalk.jar and MyTalk.jad containinig all pages of talk.pdf for the resolutions 14 and 56 Dependencies: needs ghostscript (gs) and ImageMagick (convert) installed Notes: For some phones the size of the jar file and the size of the png files are limited. On my phone those limits are 1MB and 64k, respectively. If the Midlet is not recognized by your phone or crashes upon opening a page try reducing the resolution and/or decreasing the zoom level for which tiling starts (-z 0) ... EOF } gsOPT= ztilemin=1 while getopts hf:l:z: xopt do case $xopt in h) usage exit 0;; l) gsOPT="$gsOPT -dLastPage=$OPTARG" ;; f) gsOPT="$gsOPT -dFirstPage=$OPTARG" ;; z) ztilemin=$OPTARG ;; esac done shift $(($OPTIND - 1)) if [ $# -lt 3 ]; then usage exit 1 fi infile=$1 baseout=$2 file=`basename $infile` shift 2 izoom=0 tmpdir=`mktemp -d /tmp/pdftojad.XXXXXX` while [ $# -gt 0 ]; do echo "Now doing zoom level $izoom ..." pnmfile=$tmpdir/zoom-$izoom-page- gs $gsOPT -dBATCH -dNOPAUSE -sDEVICE=pngalpha -r$1 -q -sOutputFile=$pnmfile%d.png $infile 2>/dev/null # gs $gsOPT -dBATCH -dNOPAUSE -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=png256 -r$1 -q -sOutputFile=$pnmfile%d.png $infile 2>/dev/null # gs $gsOPT -dBATCH -dNOPAUSE -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=png16m -r$1 -q -sOutputFile=$pnmfile%d.png $infile 2>/dev/null izoom=$[ izoom+1 ] shift done mkdir $tmpdir/META-INF cat >$tmpdir/META-INF/MANIFEST.MF <>$tmpdir/META-INF/MANIFEST.MF <>$tmpdir/$baseout.jad <>$tmpdir/$baseout.jad <>$baseout.jad <