public virtual void NestedExpressionTest()
        {
            PdfDocument tempDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
            // create expression with the OR operator as the first parameter
            PdfVisibilityExpression expression = new PdfVisibilityExpression(PdfName.Or);

            // add an empty dictionary as the second parameter
            expression.AddOperand(new PdfLayer((PdfDictionary) new PdfDictionary().MakeIndirect(tempDoc)));
            // create a nested expression with the AND operator and two empty dictionaries as parameters
            PdfVisibilityExpression nestedExpression = new PdfVisibilityExpression(PdfName.And);

            nestedExpression.AddOperand(new PdfLayer((PdfDictionary) new PdfDictionary().MakeIndirect(tempDoc)));
            nestedExpression.AddOperand(new PdfLayer((PdfDictionary) new PdfDictionary().MakeIndirect(tempDoc)));
            // add another expression as the third parameter
            expression.AddOperand(nestedExpression);
            PdfObject expressionObject = expression.GetPdfObject();

            NUnit.Framework.Assert.IsTrue(expressionObject is PdfArray);
            NUnit.Framework.Assert.AreEqual(3, ((PdfArray)expressionObject).Size());
            NUnit.Framework.Assert.AreEqual(PdfName.Or, ((PdfArray)expressionObject).GetAsName(0));
            PdfObject child = ((PdfArray)expressionObject).Get(2);

            NUnit.Framework.Assert.IsTrue(child is PdfArray);
            NUnit.Framework.Assert.AreEqual(3, ((PdfArray)child).Size());
            NUnit.Framework.Assert.AreEqual(PdfName.And, ((PdfArray)child).Get(0));
        }
        public virtual void AndExpressionTest()
        {
            PdfDocument tempDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
            // create expression with the AND operator as the first parameter
            PdfVisibilityExpression expression = new PdfVisibilityExpression(PdfName.And);

            // add two empty dictionaries as the other parameters
            expression.AddOperand(new PdfLayer((PdfDictionary) new PdfDictionary().MakeIndirect(tempDoc)));
            expression.AddOperand(new PdfLayer((PdfDictionary) new PdfDictionary().MakeIndirect(tempDoc)));
            PdfObject expressionObject = expression.GetPdfObject();

            NUnit.Framework.Assert.IsTrue(expressionObject is PdfArray);
            NUnit.Framework.Assert.AreEqual(3, ((PdfArray)expressionObject).Size());
            NUnit.Framework.Assert.AreEqual(PdfName.And, ((PdfArray)expressionObject).GetAsName(0));
        }
예제 #3
0
 /// <summary>
 /// Sets the visibility expression for content belonging to this
 /// membership dictionary.
 /// </summary>
 /// <param name="visibilityExpression">
 /// A (nested) array of which the first value is /And, /Or, or /Not
 /// followed by a series of indirect references to OCGs or other visibility
 /// expressions.
 /// </param>
 public virtual void SetVisibilityExpression(PdfVisibilityExpression visibilityExpression)
 {
     GetPdfObject().Put(PdfName.VE, visibilityExpression.GetPdfObject());
     GetPdfObject().SetModified();
 }