internal static int Find(this IEditablePdfDocument document, int windowSize, Func <byte[], bool> matches, int start = 0) { var end = document.Length; var pos = start; var window = new byte[windowSize]; while (pos < end) { window.Insert(document.Read(pos)); if (matches(window)) { return(pos); } pos++; } return(-1); }
internal static int FindReverse(this IEditablePdfDocument document, int windowSize, Func <byte[], bool> matches, int start) { var end = 0; var pos = start; var window = new byte[windowSize]; while (pos != end) { window.InsertReverse(document.Read(pos)); if (matches(window)) { return(pos); } pos--; } return(-1); }
public decimal ReadVersion() { var content = _document.Encoding.GetString(_document.Read(0, _document.Find(2, window => window[0] == 10 && window[1] != 37))); switch (content.Split('\n')[0]) { case "%PDF-1.4": return(1.4M); default: throw new Exception("Invalid document"); } ; }
internal static bool ByteEquals(this IEditablePdfDocument a, int posA, byte[] b, int posB) => a.Read(posA, b.Length - posB).ByteEquals(0, b, posB);