Work Process Automation – PDF to Tiff

The following Linux shell script is an example of automatic conversion of PDF files to TIFF.

The scripts looks for PDF files in an input directory and converts them to TIFF in the output directory.


# This script is 'pdf2tif'.

# It should run in the background: start it with 'pdf2tif &' from a shell or start it in the background at system boot time.
# Replace the two directories below with actual input and output directories and LOGFILE with whichever logfile is desired.
# Make sure the script has sufficient permission to read and delete the input files and to write the output files


while true
    FILE=`ls $INDIR | head -1`

    # The following sleep has a dual purpose.
    # First it prevents the script from consuming large resources.
    # Second it ensures that the input file is completely written, before we attempt to read it.
    # If input files are very large or if input files are received over a slow network, the sleep should be increased appropriately.

    sleep 5

    if [ X$FILE != X ]; then
        ecconv -export tif -resolution 300 \
        $INDIR/$FILE $OUTDIR/${FILE%.pdf}.tif

        if [ $? -ne 0 ]; then
            echo "Conversion of $FILE failed" >> $LOGFILE

        rm $INDIR/$FILE