Skip to Content

Is there a simple way to identify a file as being a PDF?

Estimated Reading Time: 1 Minutes

The first line of every PDF document is a file header with the characters “%PDF-“ followed by a version number, shown as “1.n” or "2.n", where “n” would be a digit from 0 to 7. The first line of a PDF document might look like this:

%PDF-1.7

See Section 7.5.2, “File Header,” in the ISO 32000 Reference, 1.7. Note that the "%PDF-" string is not required to be at the beginning of the file. Prior versions of Acrobat and APDFL required the "%PDF-" declaration to be within the first 1024 bytes of the file, but that arbitrary restriction has been removed. See Annex C, “Implementation Limits,” in the ISO 32000 Reference and Annex I, “PDF Versions and Compatibility”.

Note that if a Version entry in the PDF document’s catalog dictionary exists, it is used in place of the version shown in the header. The correct version value is found in the catalog.

Is there a simple way to identify a file as being a PDF?
  • COMMENT