Пример #1
0
        /**
         * <summary>Retrieves the PDF version of the file [PDF:1.6:3.4.1].</summary>
         */
        public string RetrieveVersion(
            )
        {
            stream.Seek(0);
            string header = stream.ReadString(10);

            if (!header.StartsWith(Keyword.BOF))
            {
                throw new FileFormatException("PDF header not found.", stream.Position);
            }

            return(header.Substring(Keyword.BOF.Length, 3));
        }
Пример #2
0
        /**
         * <summary>Retrieves the starting position of the last xref-table section [PDF:1.6:3.4.4].</summary>
         */
        public long RetrieveXRefOffset(
            )
        {
            IInputStream stream       = Stream;
            long         streamLength = stream.Length;
            int          chunkSize    = (int)Math.Min(streamLength, EOFMarkerChunkSize);

            // Move back before 'startxref' keyword!
            long position = streamLength - chunkSize;

            stream.Seek(position);

            // Get 'startxref' keyword position!
            int index = stream.ReadString(chunkSize).LastIndexOf(Keyword.StartXRef);

            if (index < 0)
            {
                throw new ParseException("'" + Keyword.StartXRef + "' keyword not found.", stream.Position);
            }

            // Go past the startxref keyword!
            stream.Seek(position + index); MoveNext();

            // Go to the xref offset!
            MoveNext();
            if (TokenType != TokenTypeEnum.Integer)
            {
                throw new ParseException("'" + Keyword.StartXRef + "' value invalid.", stream.Position);
            }

            return((int)Token);
        }
Пример #3
0
        /**
         * <summary>Retrieves the PDF version of the file [PDF:1.6:3.4.1].</summary>
         */
        public string RetrieveVersion()
        {
            IInputStream stream = Stream;

            stream.Seek(0);
            string header = stream.ReadString(10);

            if (!header.StartsWith(Keyword.BOF))
            {
                throw new PostScriptParseException("PDF header not found.", this);
            }

            return(header.Substring(Keyword.BOF.Length, 3));
        }
Пример #4
0
        /**
         * <summary>Retrieves the starting position of the last xref-table section [PDF:1.6:3.4.4].</summary>
         */
        public long RetrieveXRefOffset(
            )
        {
            // [FIX:69] 'startxref' keyword not found (file was corrupted by alien data in the tail).
            IInputStream stream       = Stream;
            long         streamLength = stream.Length;
            long         position     = streamLength;
            int          chunkSize    = (int)Math.Min(streamLength, EOFMarkerChunkSize);
            int          index        = -1;

            while (index < 0 && position > 0)
            {
                /*
                 * NOTE: This condition prevents the keyword from being split by the chunk boundary.
                 */
                if (position < streamLength)
                {
                    position += Keyword.StartXRef.Length;
                }
                position -= chunkSize;
                if (position < 0)
                {
                    position = 0;
                }
                stream.Seek(position);

                // Get 'startxref' keyword position!
                index = stream.ReadString(chunkSize).LastIndexOf(Keyword.StartXRef);
            }
            if (index < 0)
            {
                throw new PostScriptParseException("'" + Keyword.StartXRef + "' keyword not found.", this);
            }

            // Go past the 'startxref' keyword!
            stream.Seek(position + index); MoveNext();

            // Get the xref offset!
            MoveNext();
            if (TokenType != TokenTypeEnum.Integer)
            {
                throw new PostScriptParseException("'" + Keyword.StartXRef + "' value invalid.", this);
            }

            return((int)Token);
        }
Пример #5
0
        void IMessage.ReadFrom(IInputStream input)
        {
            uint tag;

            while ((tag = input.ReadTag()) != 0)
            {
                switch (tag)
                {
                case 9:
                    _fdouble = input.ReadDouble();
                    break;

                case 21:
                    _ffloat = input.ReadFloat();
                    break;

                case 24:
                    _fint32 = input.ReadInt32();
                    break;

                case 32:
                    _fint64 = input.ReadInt64();
                    break;

                case 40:
                    _fuint32 = input.ReadUInt32();
                    break;

                case 48:
                    _fuint64 = input.ReadUInt64();
                    break;

                case 56:
                    _fsint32 = input.ReadSInt32();
                    break;

                case 64:
                    _fsint64 = input.ReadSInt64();
                    break;

                case 77:
                    _ffixed32 = input.ReadFixed32();
                    break;

                case 81:
                    _ffixed64 = input.ReadFixed64();
                    break;

                case 93:
                    _fsfixed32 = input.ReadSFixed32();
                    break;

                case 97:
                    _fsfixed64 = input.ReadSFixed64();
                    break;

                case 104:
                    _fbool = input.ReadBool();
                    break;

                case 114:
                    _fstring = input.ReadString();
                    break;

                case 122:
                    _fbytes = input.ReadBytes();
                    break;

                case 128:
                    _fenum = (SomeEnum)input.ReadEnum();
                    break;

                case 138:
                    if (_finner == null)
                    {
                        _finner = new InnerMessage();
                    }
                    input.ReadMessage(_finner);
                    break;

                case 146:
                    if (_frep == null)
                    {
                        _frep = new global::System.Collections.Generic.List <InnerMessage>();
                    }
                    input.ReadRepeated(_frep.Add, _tinyRepeatedTypeTestroot_Classes_InnerMessage, x => _frep.Capacity = _frep.Count + x);
                    break;

                case 152:
                    if (_frepEnum == null)
                    {
                        _frepEnum = new global::System.Collections.Generic.List <SomeEnum>();
                    }
                    input.ReadRepeated(_frepEnum.Add, _tinyRepeatedTypeTestroot_Classes_TestEnum, x => _frepEnum.Capacity = _frepEnum.Count + x);
                    break;

                case 162:
                    if (_frepString == null)
                    {
                        _frepString = new global::System.Collections.Generic.List <string>();
                    }
                    input.ReadRepeated(_frepString.Add, RepeatedTypes.String, x => _frepString.Capacity = _frepString.Count + x);
                    break;

                case 173:
                    if (_frepFixed32 == null)
                    {
                        _frepFixed32 = new global::System.Collections.Generic.List <uint>();
                    }
                    input.ReadRepeated(_frepFixed32.Add, RepeatedTypes.Fixed32, x => _frepFixed32.Capacity = _frepFixed32.Count + x);
                    break;

                case 176:
                    if (_frepUint32 == null)
                    {
                        _frepUint32 = new global::System.Collections.Generic.List <uint>();
                    }
                    input.ReadRepeated(_frepUint32.Add, RepeatedTypes.UInt32, x => _frepUint32.Capacity = _frepUint32.Count + x);
                    break;

                default:
                    input.SkipField();
                    break;
                }
            }
        }