HTML info page from pdfs in a directory

Script uses pdfinfo to get information from pdf-files in directory and prints that in a webpage, put it in a webserver directory along pdfs

Prereqs: pdfinfo

#!/bin/sh
#
# Digs info from pdf and presents it in htmlpage
#
INFOCMD="/usr/bin/pdfinfo"

print_footer()
{
    echo "</body></html>"
}

# Page header
echo Content-type: text/html
echo ""
echo "<html><head><title>Available publications</title></head><body>"
if [ ! -e "$INFOCMD" ]; then
    echo "Error in exec, bailing out..."
    print_footer
    exit 1
fi
echo "<h1>Available editions</h1>"
for pdf in *.pdf
do
    echo "<p>"
    info=$($INFOCMD $pdf)
    title=$(echo "$info" | grep "Title:")
    [ -z "$title" ] || echo "$title </br>"
    subj=$(echo "$info" | grep "Subject:")
    [ -z "$subj" ] || echo "$subj </br>"
    keyw=$(echo "$info" | grep "Keywords:")
    [ -z "$keyw" ] || echo "$keyw </br>"
    echo "<a href=./$pdf>Link to pdf</a>"
    echo "</p>"
done
# Page footer
print_footer
exit 0

Leave a Reply

Your email address will not be published. Required fields are marked *