Skip to content

Instantly share code, notes, and snippets.

@andrijac
Created March 12, 2017 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrijac/2048a26f6fc7eafe578c2f690559bbbb to your computer and use it in GitHub Desktop.
Save andrijac/2048a26f6fc7eafe578c2f690559bbbb to your computer and use it in GitHub Desktop.
Check Header PDF
//http://stackoverflow.com/a/3257743/84852
public bool IsPDFHeader(string fileName)
{
byte[] buffer = null;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes = new FileInfo(fileName).Length;
//buffer = br.ReadBytes((int)numBytes);
buffer = br.ReadBytes(5);
var enc = new ASCIIEncoding();
var header = enc.GetString(buffer);
//%PDF−1.0
// If you are loading it into a long, this is (0x04034b50).
if (buffer[0] == 0x25 && buffer[1] == 0x50
&& buffer[2] == 0x44 && buffer[3] == 0x46)
{
return header.StartsWith("%PDF-");
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment