Determine if a byte[] is a pdf file Determine if a byte[] is a pdf file arrays arrays

Determine if a byte[] is a pdf file


Check the first 4 bytes of the array.

If those are 0x25 0x50 0x44 0x46 then it's most probably a PDF file.


First four bytes should be: 0x25 0x50 0x44 0x46 (in hex format, in ASCII it's %PDF). "Magic numbers" for another formats you can find here


As far as I know all PDF's start with %PDF, so you could check the first bytes against this string.