[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Computist Project: finished.



Slightly on topic...  

Here's a bash (Unix shell) script that will turn a list of JPEG files into
one PDF file.

You will need these utilities:  jpegtopnm, unpaper (optional step), pnmtops,
ps2pdf, pdftk.  They are all freely available packages.


---------------------------
#!/bin/bash
#
#  Turn a bunch of JPEG images into a single PDF file
#
#  On stdin, provide the names of the JPEG images in the order in
#  which they are to appear in the PDF file.
#
#  Usage:
#   echo names of all JPEG files | jpegs2pdf output.pdf

OUTFILE="$1"

WORK=/tmp/makepdf-$$
PNM1=${WORK}/1.pnm
PNM2=${WORK}/2.pnm
ERR=${WORK}/error-output
mkdir -p ${WORK}
trap "rm -fr ${WORK}" 1 2 15

typeset -i page maxpage

page=1

pages=""
while read line; do
  set ${line}
  while [ -n "$1" ]; do
    jpeg="$1"
    shift
    PDFPAGE=${WORK}/page-${page}
    jpegtopnm ${jpeg} >${PNM1}
    unpaper ${PNM1} ${PNM2} 1>&2
    pnmtops -imagewidth 7.5 ${PNM2} |ps2pdf - - >${PDFPAGE}
    rm -f ${PNM1} ${PNM2}
    pages="${pages} ${PDFPAGE}"
    maxpage=${page}
    page=page+1
  done
done 2>${ERR}

pdftk ${pages} cat output ${OUTFILE} 2>>${ERR}