public virtual void PdtIndirectReferenceLateInitializing2()
        {
            MemoryStream baos     = new MemoryStream();
            PdfDocument  document = new PdfDocument(new PdfWriter(baos));

            document.AddNewPage();
            PdfDictionary        catalog = document.GetCatalog().GetPdfObject();
            PdfIndirectReference indRef1 = document.CreateNextIndirectReference();
            PdfIndirectReference indRef2 = document.CreateNextIndirectReference();

            catalog.Put(new PdfName("Smth1"), indRef1);
            catalog.Put(new PdfName("Smth2"), indRef2);
            PdfArray array = new PdfArray();

            array.Add(new PdfString("array string"));
            array.MakeIndirect(document, indRef2);
            document.Close();
            MemoryStream bais = new MemoryStream(baos.ToArray());

            document = new PdfDocument(new PdfReader(bais));
            PdfDictionary catalogDict = document.GetCatalog().GetPdfObject();
            PdfObject     object1     = catalogDict.Get(new PdfName("Smth1"));
            PdfObject     object2     = catalogDict.Get(new PdfName("Smth2"));

            NUnit.Framework.Assert.IsTrue(object1 is PdfNull);
            NUnit.Framework.Assert.IsTrue(object2 is PdfArray);
        }
Beispiel #2
0
        public virtual void SmartModeObjectSelfReferencingTest()
        {
            PdfDocument   document = new PdfDocument(new PdfWriter(new MemoryStream()));
            PdfDictionary dict1    = new PdfDictionary();

            dict1.MakeIndirect(document);
            PdfDictionary dict2 = new PdfDictionary();

            dict2.MakeIndirect(document);
            PdfArray array = new PdfArray();

            array.MakeIndirect(document);
            array.Add(new PdfString(new byte[10000]));
            array.Add(new PdfDictionary(dict2));
            dict1.Put(new PdfName("FirstDict"), array.GetIndirectReference());
            dict2.Put(new PdfName("SecondDict"), dict1.GetIndirectReference());
            SmartModePdfObjectsSerializer serializer       = new SmartModePdfObjectsSerializer();
            SerializedObjectContent       serializedObject = serializer.SerializeObject(dict1);
            //It is essential to serialize object with huge amount of memory
            StringBuilder stringBytes = new StringBuilder().Append("$D$N/FirstDict$A$S");
            String        end         = "$D$\\D$\\A$\\D";

            for (int i = 0; i < 10000; i++)
            {
                stringBytes.Append("\x0");
            }
            stringBytes.Append(end);
            SerializedObjectContent expected = new SerializedObjectContent(stringBytes.ToString().GetBytes(System.Text.Encoding
                                                                                                           .UTF8));

            NUnit.Framework.Assert.AreEqual(expected, serializedObject);
        }
Beispiel #3
0
        public virtual void FlushSelfContainingObjectsWritingMode()
        {
            PdfDocument   pdfDoc   = new PdfDocument(new PdfWriter(new MemoryStream()));
            PdfDictionary pageDict = pdfDoc.AddNewPage().GetPdfObject();
            PdfDictionary dict1    = new PdfDictionary();

            pageDict.Put(new PdfName("dict1"), dict1);
            PdfArray arr1 = new PdfArray();

            pageDict.Put(new PdfName("arr1"), arr1);
            dict1.Put(new PdfName("dict1"), dict1);
            dict1.Put(new PdfName("arr1"), arr1);
            arr1.Add(arr1);
            arr1.Add(dict1);
            arr1.MakeIndirect(pdfDoc);
            dict1.MakeIndirect(pdfDoc);
            PageFlushingHelper flushingHelper = new PageFlushingHelper(pdfDoc);

            flushingHelper.UnsafeFlushDeep(1);
            NUnit.Framework.Assert.IsTrue(dict1.IsFlushed());
            NUnit.Framework.Assert.IsTrue(arr1.IsFlushed());
            pdfDoc.Close();
        }