Пример #1
0
        public virtual void TestContains()
        {
            PdfDocument doc   = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
            PdfArray    array = new PdfArray();

            array.Add(new PdfNumber(1).MakeIndirect(doc).GetIndirectReference());
            array.Add(new PdfNumber(2).MakeIndirect(doc).GetIndirectReference());
            array.Add(new PdfNumber(3).MakeIndirect(doc));
            array.Add(new PdfNumber(4).MakeIndirect(doc));
            array.Add(new PdfNumber(5));
            array.Add(new PdfNumber(6));
            PdfArray array2 = new PdfArray();

            array2.Add(new PdfNumber(1).MakeIndirect(doc).GetIndirectReference());
            array2.Add(new PdfNumber(2).MakeIndirect(doc).GetIndirectReference());
            array2.Add(new PdfNumber(3).MakeIndirect(doc));
            array2.Add(new PdfNumber(4).MakeIndirect(doc));
            array2.Add(new PdfNumber(5));
            array2.Add(new PdfNumber(6));
            foreach (PdfObject obj in array2)
            {
                NUnit.Framework.Assert.IsTrue(array.Contains(obj));
            }
            for (int i = 0; i < array2.Size(); i++)
            {
                NUnit.Framework.Assert.IsTrue(array.Contains(array2.Get(i)));
            }
        }
Пример #2
0
        /// <summary>Removes an annotation from the page.</summary>
        /// <remarks>
        /// Removes an annotation from the page.
        /// <br /><br />
        /// NOTE: If document is tagged, PdfDocument's PdfTagStructure instance will point at annotation tag parent after method call.
        /// </remarks>
        /// <param name="annotation">an annotation to be removed.</param>
        /// <returns>this PdfPage instance.</returns>
        public virtual iText.Kernel.Pdf.PdfPage RemoveAnnotation(PdfAnnotation annotation)
        {
            PdfArray annots = GetAnnots(false);

            if (annots != null)
            {
                if (annots.Contains(annotation.GetPdfObject()))
                {
                    annots.Remove(annotation.GetPdfObject());
                }
                else
                {
                    annots.Remove(annotation.GetPdfObject().GetIndirectReference());
                }
                if (annots.IsEmpty())
                {
                    GetPdfObject().Remove(PdfName.Annots);
                }
            }
            if (GetDocument().IsTagged())
            {
                TagTreePointer tagPointer = GetDocument().GetTagStructureContext().RemoveAnnotationTag(annotation);
                if (tagPointer != null)
                {
                    bool standardAnnotTagRole = tagPointer.GetRole().Equals(PdfName.Annot) || tagPointer.GetRole().Equals(PdfName
                                                                                                                          .Form);
                    if (tagPointer.GetKidsRoles().Count == 0 && standardAnnotTagRole)
                    {
                        tagPointer.RemoveTag();
                    }
                }
            }
            return(this);
        }
Пример #3
0
        public virtual void TestValuesIndirectContains()
        {
            PdfDocument doc   = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
            PdfArray    array = new PdfArray();

            array.Add(new PdfNumber(0).MakeIndirect(doc).GetIndirectReference());
            array.Add(new PdfNumber(1).MakeIndirect(doc).GetIndirectReference());
            array.Add(new PdfNumber(2).MakeIndirect(doc));
            array.Add(new PdfNumber(3).MakeIndirect(doc));
            array.Add(new PdfNumber(4));
            array.Add(new PdfNumber(5));
            NUnit.Framework.Assert.IsTrue(array.Contains(array.Get(0, false)));
            NUnit.Framework.Assert.IsTrue(array.Contains(array.Get(1, false)));
            NUnit.Framework.Assert.IsTrue(array.Contains(array.Get(2).GetIndirectReference()));
            NUnit.Framework.Assert.IsTrue(array.Contains(array.Get(3).GetIndirectReference()));
            NUnit.Framework.Assert.IsTrue(array.Contains(array.Get(4)));
            NUnit.Framework.Assert.IsTrue(array.Contains(array.Get(5)));
        }