예제 #1
0
        public DictionaryObject(Tokenizer tokenizer)
        {
            Token token;

            if (!TokenValidator.IsDelimiter(tokenizer.TokenExcludedCommentsAndWhitespaces(), "<"))
            {
                throw new PdfException(PdfExceptionCodes.INVALID_DICTIONARY, "Expected <");
            }
            if (!TokenValidator.IsDelimiter(tokenizer.TokenExcludedComments(), "<"))
            {
                throw new PdfException(PdfExceptionCodes.INVALID_DICTIONARY, "Expected <");
            }

            while (!tokenizer.IsNextTokenExcludedCommentsAndWhitespaces(">"))
            {
                ReadKeyValue(tokenizer);
            }

            tokenizer.TokenExcludedCommentsAndWhitespaces();            // first >

            if (!TokenValidator.IsDelimiter(tokenizer.TokenExcludedComments(), ">"))
            {
                throw new PdfException(PdfExceptionCodes.INVALID_DICTIONARY, "Expected >");
            }

            if (HasStream)
            {
                if (!TokenValidator.Validate(tokenizer.TokenExcludedCommentsAndWhitespaces(), "stream"))
                {
                    throw new PdfException(PdfExceptionCodes.INVALID_DICTIONARY_STREAM, "A dictionary with Lenght hasnt stream object");
                }

                if (!tokenizer.ReadIntro())
                {
                    throw new PdfException(PdfExceptionCodes.INVALID_DICTIONARY_STREAM, "A stream must be followed by \\n or \\r\\n");
                }

                stream = tokenizer.ReadStream(streamLength.Value);
                if (dictionary.ContainsKey("Filter"))
                {
                    if (((NameObject)dictionary["Filter"]).Value == "FlateDecode")
                    {
                        int predictor = 1;

                        if (dictionary.ContainsKey("Predictor"))
                        {
                            predictor = ((IntegerObject)dictionary["Predictor"]).IntValue;
                        }

                        stream = Deflate(stream, predictor, 0);
                    }
                }

                token = tokenizer.TokenExcludedCommentsAndWhitespaces();
                if (!TokenValidator.Validate(token, "endstream"))
                {
                    throw new PdfException(PdfExceptionCodes.INVALID_DICTIONARY_STREAM, $"Expected endstream but {token} found");
                }
            }
        }
예제 #2
0
        public ArrayObject(Tokenizer tokenizer)
        {
            if (!TokenValidator.IsDelimiter(tokenizer.TokenExcludedCommentsAndWhitespaces(), "["))
            {
                throw new PdfException(PdfExceptionCodes.INVALID_ARRAY, "Expected [");
            }

            var read = new Objectizer(tokenizer);

            while (!tokenizer.IsNextTokenExcludedCommentsAndWhitespaces("]"))
            {
                childs.Add(read.NextObject());
            }

            if (!TokenValidator.IsDelimiter(tokenizer.TokenExcludedCommentsAndWhitespaces(), "]"))
            {
                throw new PdfException(PdfExceptionCodes.INVALID_ARRAY, "Expected ]");
            }
        }