/// <exception cref="System.IO.IOException"/> private void ValidateUseObjectForMultipleTimesTest(String filename) { PdfReader reader = new PdfReader(filename); PdfDocument pdfDoc = new PdfDocument(reader); NUnit.Framework.Assert.AreEqual(false, reader.HasRebuiltXref(), "Rebuilt"); PdfDictionary page = pdfDoc.GetPage(1).GetPdfObject(); NUnit.Framework.Assert.IsNotNull(page); PdfDictionary helloWorld = page.GetAsDictionary(new PdfName("HelloWorld")); NUnit.Framework.Assert.IsNotNull(helloWorld); PdfString world = helloWorld.GetAsString(new PdfName("Hello")); NUnit.Framework.Assert.AreEqual("World", world.ToString()); helloWorld = pdfDoc.GetCatalog().GetPdfObject().GetAsDictionary(new PdfName("HelloWorld")); NUnit.Framework.Assert.IsNotNull(helloWorld); world = helloWorld.GetAsString(new PdfName("Hello")); NUnit.Framework.Assert.AreEqual("World", world.ToString()); reader.Close(); }
public virtual void Copying3() { FileStream fos = new FileStream(destinationFolder + "copying3_1.pdf", FileMode.Create); PdfWriter writer = new PdfWriter(fos); PdfDocument pdfDoc = new PdfDocument(writer); PdfDictionary helloWorld = ((PdfDictionary) new PdfDictionary().MakeIndirect(pdfDoc)); PdfDictionary helloWorld1 = ((PdfDictionary) new PdfDictionary().MakeIndirect(pdfDoc)); helloWorld.Put(new PdfName("Hello"), new PdfString("World")); helloWorld.Put(new PdfName("HelloWrld"), helloWorld); helloWorld.Put(new PdfName("HelloWrld1"), helloWorld1); PdfPage page = pdfDoc.AddNewPage(); page.GetPdfObject().Put(new PdfName("HelloWorld"), helloWorld); page.GetPdfObject().Put(new PdfName("HelloWorldClone"), (PdfObject)helloWorld.Clone()); pdfDoc.Close(); PdfReader reader = new PdfReader(destinationFolder + "copying3_1.pdf"); NUnit.Framework.Assert.AreEqual(false, reader.HasRebuiltXref(), "Rebuilt"); pdfDoc = new PdfDocument(reader); PdfDictionary dic0 = pdfDoc.GetPage(1).GetPdfObject().GetAsDictionary(new PdfName("HelloWorld")); NUnit.Framework.Assert.AreEqual(4, dic0.GetIndirectReference().GetObjNumber()); NUnit.Framework.Assert.AreEqual(0, dic0.GetIndirectReference().GetGenNumber()); PdfDictionary dic1 = pdfDoc.GetPage(1).GetPdfObject().GetAsDictionary(new PdfName("HelloWorldClone")); NUnit.Framework.Assert.AreEqual(8, dic1.GetIndirectReference().GetObjNumber()); NUnit.Framework.Assert.AreEqual(0, dic1.GetIndirectReference().GetGenNumber()); PdfString str0 = dic0.GetAsString(new PdfName("Hello")); PdfString str1 = dic1.GetAsString(new PdfName("Hello")); NUnit.Framework.Assert.AreEqual(str0.GetValue(), str1.GetValue()); NUnit.Framework.Assert.AreEqual(str0.GetValue(), "World"); PdfDictionary dic01 = dic0.GetAsDictionary(new PdfName("HelloWrld")); PdfDictionary dic11 = dic1.GetAsDictionary(new PdfName("HelloWrld")); NUnit.Framework.Assert.AreEqual(dic01.GetIndirectReference().GetObjNumber(), dic11.GetIndirectReference(). GetObjNumber()); NUnit.Framework.Assert.AreEqual(dic01.GetIndirectReference().GetGenNumber(), dic11.GetIndirectReference(). GetGenNumber()); NUnit.Framework.Assert.AreEqual(dic01.GetIndirectReference().GetObjNumber(), 4); NUnit.Framework.Assert.AreEqual(dic01.GetIndirectReference().GetGenNumber(), 0); PdfDictionary dic02 = dic0.GetAsDictionary(new PdfName("HelloWrld1")); PdfDictionary dic12 = dic1.GetAsDictionary(new PdfName("HelloWrld1")); NUnit.Framework.Assert.AreEqual(dic02.GetIndirectReference().GetObjNumber(), dic12.GetIndirectReference(). GetObjNumber()); NUnit.Framework.Assert.AreEqual(dic02.GetIndirectReference().GetGenNumber(), dic12.GetIndirectReference(). GetGenNumber()); NUnit.Framework.Assert.AreEqual(dic12.GetIndirectReference().GetObjNumber(), 5); NUnit.Framework.Assert.AreEqual(dic12.GetIndirectReference().GetGenNumber(), 0); reader.Close(); }
public virtual void ReadEncryptedDocumentWithFullCompression() { PdfReader reader = new PdfReader(sourceFolder + "source.pdf", new ReaderProperties().SetPassword("123".GetBytes ())); PdfDocument pdfDocument = new PdfDocument(reader); PdfDictionary form = pdfDocument.GetCatalog().GetPdfObject().GetAsDictionary(PdfName.AcroForm); PdfDictionary field = form.GetAsArray(PdfName.Fields).GetAsDictionary(0); NUnit.Framework.Assert.AreEqual("ch", field.GetAsString(PdfName.T).ToUnicodeString()); NUnit.Framework.Assert.AreEqual("SomeStringValueInDictionary", field.GetAsDictionary(new PdfName("TestDic" )).GetAsString(new PdfName("TestString")).ToUnicodeString()); NUnit.Framework.Assert.AreEqual("SomeStringValueInArray", field.GetAsArray(new PdfName("TestArray")).GetAsString (0).ToUnicodeString()); pdfDocument.Close(); }
private String GetStringValue(PdfName name) { PdfString pdfString = infoDictionary.GetAsString(name); return(pdfString != null?pdfString.ToUnicodeString() : null); }