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));
        }
Exemplo n.º 2
0
        public virtual void DisabledVisualExpressionTest01()
        {
            String      srcPdf  = "sourceWithDifferentLayers.pdf";
            String      destPdf = "disabledVisualExpressionTest01.pdf";
            String      cmpPdf  = "cmp_" + destPdf;
            PdfDocument pdfDoc  = new PdfDocument(new PdfReader(sourceFolder + srcPdf), new PdfWriter(destinationFolder
                                                                                                      + destPdf));
            PdfCanvas canvas = new PdfCanvas(pdfDoc.GetFirstPage());

            canvas.SetFontAndSize(PdfFontFactory.CreateFont(StandardFonts.HELVETICA), 18);
            IList <PdfLayer>   allLayers            = pdfDoc.GetCatalog().GetOCProperties(true).GetLayers();
            PdfLayerMembership layerMembershipAnyOn = new PdfLayerMembership(pdfDoc);
            // create expression with the AND operator as the first operand
            PdfVisibilityExpression expression = new PdfVisibilityExpression(PdfName.And);

            // add an empty dictionary as the second operand
            expression.AddOperand(allLayers[1]);
            // create a nested expression with the AND operator and two empty dictionaries as operands
            PdfVisibilityExpression nestedExpression = new PdfVisibilityExpression(PdfName.And);

            nestedExpression.AddOperand(allLayers[0]);
            nestedExpression.AddOperand(allLayers[2]);
            // add another expression as the third operand
            expression.AddOperand(nestedExpression);
            layerMembershipAnyOn.AddLayer(allLayers[0]);
            layerMembershipAnyOn.AddLayer(allLayers[1]);
            layerMembershipAnyOn.SetVisibilityExpression(expression);
            PdfLayerTestUtils.AddTextInsideLayer(layerMembershipAnyOn, canvas, "visualExpressionTest01", 200, 500);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destPdf, sourceFolder
                                                                             + cmpPdf, destinationFolder));
        }
        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));
        }
Exemplo n.º 4
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();
 }