Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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");
            }
            ;
        }
Ejemplo n.º 4
0
 internal static bool ByteEquals(this IEditablePdfDocument a, int posA, byte[] b, int posB) => a.Read(posA, b.Length - posB).ByteEquals(0, b, posB);