Reputation: 23275
Using perl
, what is the best way to determine whether a file is a PDF
?
Apparently, not all PDFs
start with %PDF
. See the comments on this answer: https://stackoverflow.com/a/941962/327528
Upvotes: 2
Views: 816
Reputation: 625
Detecting a PDF is not hard, but there are some corner cases to be aware of.
In sum, read in the first and last 1kb of the file into a byte buffer, check that the relevant identifying byte string tokens are approximately where they are supposed to be and if they are then you have a reasonable expectation that you have a PDF file on your hands.
Upvotes: 1
Reputation: 2035
The module PDF::Parse has method called IsaPDF which
Returns true, if the file could be parsed and is a PDF-file.
Upvotes: 0