in reply to opening a file for printing

You mean the database doesn't know the type of the file it accepted at input time? Ouch.

You need a heuristic, which as Dominus puts it "is a fancy way of saying that it doesn't work".

File::MimeInfo::Magic might do what you want.