SignatureClipper { public static boolean clipSignature(PDField field) { if (nonNull(field) && COSName.SIG.getName().equals(field.getFieldType())) { clipSignature(field.getCOSObject()); return true; } return false; } private  SignatureClipper(); static void clipSignatures(Collection<PDAnnotation> annotations); static void clipSignatures(PDDocument doc); static boolean clipSignature(PDField field);  }
@Test public void nullFieldDoesntFail() { assertFalse(SignatureClipper.clipSignature(null)); }
@Test public void clipField() { PDField field = PDFieldFactory.createFieldAddingChildToParent(new PDAcroForm(new PDDocument()), dictionary, null); assertTrue(SignatureClipper.clipSignature(field)); assertFalse(field.getCOSObject().containsKey(COSName.V)); assertFalse(field.getCOSObject().containsKey(COSName.SV)); assertFalse(field.getCOSObject().containsKey(COSName.LOCK)); }
@Test public void clipFieldNotSignature() { dictionary.setItem(COSName.FT, COSName.BTN); PDField field = PDFieldFactory.createFieldAddingChildToParent(new PDAcroForm(new PDDocument()), dictionary, null); SignatureClipper.clipSignature(field); assertTrue(field.getCOSObject().containsKey(COSName.V)); assertTrue(field.getCOSObject().containsKey(COSName.SV)); assertTrue(field.getCOSObject().containsKey(COSName.LOCK)); }