PdfVisibilityExpression extends PdfObjectWrapper<PdfArray> { public void addOperand(PdfLayer layer) { getPdfObject().add(layer.getPdfObject()); getPdfObject().setModified(); } PdfVisibilityExpression(PdfArray visibilityExpressionArray);  PdfVisibilityExpression(PdfName operator); void addOperand(PdfLayer layer); void addOperand(PdfVisibilityExpression expression);  }
@Test public void andExpressionTest() { PdfDocument tempDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream())); PdfVisibilityExpression expression = new PdfVisibilityExpression(PdfName.And); expression.addOperand(new PdfLayer((PdfDictionary) new PdfDictionary().makeIndirect(tempDoc))); expression.addOperand(new PdfLayer((PdfDictionary) new PdfDictionary().makeIndirect(tempDoc))); PdfObject expressionObject = expression.getPdfObject(); Assert.assertTrue(expressionObject instanceof PdfArray); Assert.assertEquals(3, ((PdfArray) expressionObject).size()); Assert.assertEquals(PdfName.And, ((PdfArray) expressionObject).getAsName(0)); }
@Test public void nestedExpressionTest() { PdfDocument tempDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream())); PdfVisibilityExpression expression = new PdfVisibilityExpression(PdfName.Or); expression.addOperand(new PdfLayer((PdfDictionary) new PdfDictionary().makeIndirect(tempDoc))); PdfVisibilityExpression nestedExpression = new PdfVisibilityExpression(PdfName.And); nestedExpression.addOperand(new PdfLayer((PdfDictionary) new PdfDictionary().makeIndirect(tempDoc))); nestedExpression.addOperand(new PdfLayer((PdfDictionary) new PdfDictionary().makeIndirect(tempDoc))); expression.addOperand(nestedExpression); PdfObject expressionObject = expression.getPdfObject(); Assert.assertTrue(expressionObject instanceof PdfArray); Assert.assertEquals(3, ((PdfArray) expressionObject).size()); Assert.assertEquals(PdfName.Or, ((PdfArray) expressionObject).getAsName(0)); PdfObject child = ((PdfArray) expressionObject).get(2); Assert.assertTrue(child instanceof PdfArray); Assert.assertEquals(3, ((PdfArray) child).size()); Assert.assertEquals(PdfName.And, ((PdfArray) child).get(0)); }