示例#1
0
        public virtual void TestUnicodeString()
        {
            String    unicode = "Привет!";
            PdfString @string = new PdfString(unicode);

            NUnit.Framework.Assert.AreNotEqual(unicode, @string.ToUnicodeString());
        }
示例#2
0
        public virtual void EncodingTest()
        {
            RandomAccessSourceFactory factory;
            PdfTokenizer tok;
            PdfString    pdfString;
            // hex string parse and check
            String testHexString = "<0D0A09557365729073204775696465>";

            factory = new RandomAccessSourceFactory();
            tok     = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(testHexString.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));
            tok.NextToken();
            pdfString = new PdfString(tok.GetByteContent(), tok.IsHexString());
            NUnit.Framework.Assert.AreEqual("\r\n\tUser\u0090s Guide", pdfString.GetValue());
            String testUnicodeString = "ΑΒΓΗ€•♣⋅";

            pdfString = new PdfString(PdfEncodings.ConvertToBytes(testUnicodeString, PdfEncodings.UNICODE_BIG), false);
            NUnit.Framework.Assert.AreEqual(testUnicodeString, pdfString.ToUnicodeString());
            pdfString = new PdfString("FEFF041F04400438043204350442".GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1),
                                      true);
            NUnit.Framework.Assert.AreEqual("\u041F\u0440\u0438\u0432\u0435\u0442", pdfString.ToUnicodeString());
            pdfString = new PdfString("FEFF041F04400438043204350442".GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1),
                                      false);
            NUnit.Framework.Assert.AreEqual("FEFF041F04400438043204350442", pdfString.ToUnicodeString());
            String specialCharacter = "\r\n\t\\n\\r\\t\\f";

            pdfString = new PdfString(specialCharacter.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1), false);
            NUnit.Framework.Assert.AreEqual("\n\t\n\r\t\f", pdfString.ToUnicodeString());
            String symbol = "\u0001\u0004\u0006\u000E\u001F";

            pdfString = new PdfString(symbol.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1), false);
            NUnit.Framework.Assert.AreEqual(symbol, pdfString.ToUnicodeString());
            String testString1 = "These\\\n two\\\r strings\\\n are the same";

            pdfString = new PdfString(testString1.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1), false);
            NUnit.Framework.Assert.AreEqual("These two strings are the same", pdfString.GetValue());
            String testString2 = "This string contains \\245two octal characters\\307";

            pdfString = new PdfString(testString2.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1), false);
            NUnit.Framework.Assert.AreEqual("This string contains \u00A5two octal characters\u00C7", pdfString.GetValue
                                                ());
            String testString3 = "\\0053";

            pdfString = new PdfString(testString3.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1), false);
            NUnit.Framework.Assert.AreEqual("\u00053", pdfString.GetValue());
            String testString4 = "\\053";

            pdfString = new PdfString(testString4.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1), false);
            NUnit.Framework.Assert.AreEqual("+", pdfString.GetValue());
            byte[] b = new byte[] { (byte)46, (byte)56, (byte)40 };
            pdfString = new PdfString(b, false);
            NUnit.Framework.Assert.AreEqual(iText.IO.Util.JavaUtil.GetStringForBytes(b), pdfString.GetValue());
        }
示例#3
0
        private String GetStringValue(PdfName name)
        {
            PdfString pdfString = infoDictionary.GetAsString(name);

            return(pdfString != null?pdfString.ToUnicodeString() : null);
        }
示例#4
0
        private String GetStringValue(PdfName name)
        {
            PdfString pdfString = GetPdfObject().GetAsString(name);

            return(pdfString != null?pdfString.ToUnicodeString() : null);
        }