#!/bin/sh # Script to convert directory of images onto a single PDF # Software dependencies: pdftk, imagemagick # Usage: ./imgs2pdf.sh imgs-dir-name pdf-filename # if no pdf-filename is provided, output.pdf will the default file name DIR="" FILENAME="" echo ${#1} if [ ${#1} -gt 0 ] # check arguments given then DIR=$1 echo "Images from $DIR directory are being converted onto PDF" if [ ${#2} -gt 0 ] then FILENAME=$2 else FILENAME=output.pdf fi echo "under the filename: $FILENAME" PROCESS=true else echo "You forgot to provide the images directory as the first argument" PROCESS=false fi if $PROCESS true; then echo "processing..." for IMG in $DIR* # convert imgs to tmp pdfs do PDF=${IMG%.*}.pdf # convert -density 200 $IMG $PDF done pdftk $DIR*.pdf cat output $FILENAME # concatonate single pdf into 1 pdf fi