Exemplo n.º 1
0
 /// <summary>Check whether line starts with object declaration.</summary>
 /// <param name="lineTokenizer">tokenizer, built by single line.</param>
 /// <returns>object number and generation if check is successful, otherwise - null.</returns>
 public static int[] CheckObjectStart(PdfTokenizer lineTokenizer)
 {
     try {
         lineTokenizer.Seek(0);
         if (!lineTokenizer.NextToken() || lineTokenizer.GetTokenType() != PdfTokenizer.TokenType.Number)
         {
             return(null);
         }
         int num = lineTokenizer.GetIntValue();
         if (!lineTokenizer.NextToken() || lineTokenizer.GetTokenType() != PdfTokenizer.TokenType.Number)
         {
             return(null);
         }
         int gen = lineTokenizer.GetIntValue();
         if (!lineTokenizer.NextToken())
         {
             return(null);
         }
         if (!JavaUtil.ArraysEquals(Obj, lineTokenizer.GetByteContent()))
         {
             return(null);
         }
         return(new int[] { num, gen });
     }
     catch (Exception) {
     }
     // empty on purpose
     return(null);
 }
Exemplo n.º 2
0
        private void CheckTokenValues(String data, params byte[][] expectedValues)
        {
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            for (int i = 0; i < expectedValues.Length; i++)
            {
                tok.NextValidToken();
                NUnit.Framework.Assert.AreEqual(expectedValues[i], tok.GetByteContent(), "Position " + i);
            }
        }
Exemplo n.º 3
0
        public virtual void PrimitivesTest()
        {
            String data = "<</Size 70.%comment\n" + "/Value#20 .1" + "/Root 46 0 R" + "/Info 44 0 R" + "/ID[<736f6d652068657820737472696e672>(some simple string )<8C2547D58D4BD2C6F3D32B830BE3259D2>-70.1--0.2]"
                          + "/Name1 --15" + "/Prev ---116.23 >>";
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.StartDic, tok.GetTokenType());
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Size", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("70.", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Value#20", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent())
                                            );
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual(".1", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Root", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Ref, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("46 0 R", "" + tok.GetObjNr() + " " + tok.GetGenNr() + " " + iText.IO.Util.JavaUtil.GetStringForBytes
                                                (tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Info", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Ref, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("44 0 R", "" + tok.GetObjNr() + " " + tok.GetGenNr() + " " + iText.IO.Util.JavaUtil.GetStringForBytes
                                                (tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("ID", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.StartArray, tok.GetTokenType());
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.String, tok.GetTokenType());
            NUnit.Framework.Assert.IsTrue(tok.IsHexString());
            NUnit.Framework.Assert.AreEqual("736f6d652068657820737472696e672", iText.IO.Util.JavaUtil.GetStringForBytes
                                                (tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.String, tok.GetTokenType());
            NUnit.Framework.Assert.IsFalse(tok.IsHexString());
            NUnit.Framework.Assert.AreEqual("some simple string ", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent
                                                                                                                ()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.String, tok.GetTokenType());
            NUnit.Framework.Assert.IsTrue(tok.IsHexString());
            NUnit.Framework.Assert.AreEqual("8C2547D58D4BD2C6F3D32B830BE3259D2", iText.IO.Util.JavaUtil.GetStringForBytes
                                                (tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("-70.1", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("-0.2", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.EndArray, tok.GetTokenType());
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Name1", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("0", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Name, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Prev", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(PdfTokenizer.TokenType.Number, tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("-116.23", iText.IO.Util.JavaUtil.GetStringForBytes(tok.GetByteContent()));
        }