#!/bin/sh
# $Id: restore-pdf-mtime,v 1.2 2018/12/11 00:05:17 friedman Exp $

readmtime()
{
    awk -F' *:  *' \
        -e '/^ModDate:/ { print $2; exit }' \
        -e '/^CreationDate:/ { tm=$2 }' \
        -e 'ENDFILE { print tm }'
}

for pdf in "$@"; do
    tm=`pdfinfo "$pdf" | readmtime`
    case $tm in "" ) continue ;; esac
    touch -d "$tm" "$pdf"
done
