Example #1
0
        internal IPDFObject GetObject(int index)
        {
            if (index < 0 || index >= _entries.Count)
            {
                return(null);
            }

            Entry entry = _entries[index];

            if (entry == null)
            {
                return(null);
            }

            if (entry.Object != null)
            {
                return(entry.Object);
            }

            if (entry.EntryType == 2)
            {
                parseGenerationEntry(entry);
                if (entry.Object == null)
                {
                    return(entry.Object = new PDFNull());
                }
                return(entry.Object);
            }
            else
            {
                IPDFObject obj = _lexer.ParseEntry(index, entry.Offset, entry.Generation);
                if (obj == null)
                {
                    obj = new PDFNull();
                }

                entry.Object = obj;
                return(obj);
            }
        }
Example #2
0
        private void parseGenerationEntry(Entry entry)
        {
            PDFDictionaryStream dictStream = GetObject(entry.Offset) as PDFDictionaryStream;

            if (dictStream != null)
            {
                PDFNumber n = dictStream.Dictionary["N"] as PDFNumber;
                if (n == null)
                {
                    return;
                }
                int count = (int)n.GetValue();
                if (count <= 0)
                {
                    return;
                }

                n = dictStream.Dictionary["First"] as PDFNumber;
                if (n == null)
                {
                    return;
                }
                int first = (int)n.GetValue();
                if (first < 0)
                {
                    return;
                }

                dictStream.Decode();
                List <int> objects = new List <int>();
                List <int> offsets = new List <int>();

                Lexer lexer = new Lexer(dictStream.GetStream(), this, null, 512);
                lexer.Position = 0;

                for (int i = 0; i < count; ++i)
                {
                    bool succes;
                    int  objNo = lexer.ReadInteger(out succes);
                    if (!succes)
                    {
                        break;
                    }
                    int offset = lexer.ReadInteger(out succes);
                    if (!succes)
                    {
                        break;
                    }
                    objects.Add(objNo);
                    offsets.Add(offset);
                }

                int l = objects.Count;
                for (int i = 0; i < l; ++i)
                {
                    lexer.Position = offsets[i] + first;
                    IPDFObject obj = lexer.ReadObject();
                    if (obj == null)
                    {
                        obj = new PDFNull();
                    }

                    int index = objects[i];
                    if (index >= 0 && index < _entries.Count)
                    {
                        if (_entries[index] == null)
                        {
                            _entries[index] = new Entry(0, 0);
                        }
                        if (entry.Offset == _entries[index].Offset)
                        {
                            _entries[index].Object = obj;
                        }
                    }
                }
            }
        }