Created
March 12, 2017 11:04
-
-
Save andrijac/2048a26f6fc7eafe578c2f690559bbbb to your computer and use it in GitHub Desktop.
Check Header PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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