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 ResourcesTest2()
        {
            MemoryStream baos      = new MemoryStream();
            PdfDocument  document  = new PdfDocument(new PdfWriter(baos));
            PdfPage      page      = document.AddNewPage();
            PdfExtGState egs1      = new PdfExtGState();
            PdfExtGState egs2      = new PdfExtGState();
            PdfResources resources = page.GetResources();

            resources.AddExtGState(egs1);
            resources.AddExtGState(egs2);
            document.Close();
            PdfReader reader = new PdfReader(new MemoryStream(baos.ToArray()));

            document  = new PdfDocument(reader, new PdfWriter(new ByteArrayOutputStream()));
            page      = document.GetPage(1);
            resources = page.GetResources();
            ICollection <PdfName> names = resources.GetResourceNames();

            NUnit.Framework.Assert.AreEqual(2, names.Count);
            String[] expectedNames = new String[] { "Gs1", "Gs2" };
            int      i             = 0;

            foreach (PdfName name in names)
            {
                NUnit.Framework.Assert.AreEqual(expectedNames[i++], name.GetValue());
            }
            PdfExtGState egs3 = new PdfExtGState();
            PdfName      n3   = resources.AddExtGState(egs3);

            NUnit.Framework.Assert.AreEqual("Gs3", n3.GetValue());
            PdfDictionary egsResources = page.GetPdfObject().GetAsDictionary(PdfName.Resources).GetAsDictionary(PdfName
                                                                                                                .ExtGState);
            PdfDictionary e1 = egsResources.GetAsDictionary(new PdfName("Gs1"));
            PdfName       n1 = resources.AddExtGState(e1);

            NUnit.Framework.Assert.AreEqual("Gs1", n1.GetValue());
            PdfDictionary e2 = egsResources.GetAsDictionary(new PdfName("Gs2"));
            PdfName       n2 = resources.AddExtGState(e2);

            NUnit.Framework.Assert.AreEqual("Gs2", n2.GetValue());
            PdfDictionary e4 = (PdfDictionary)e2.Clone();
            PdfName       n4 = resources.AddExtGState(e4);

            NUnit.Framework.Assert.AreEqual("Gs4", n4.GetValue());
            document.Close();
        }