After redaction is done spaces are removed between words, which are before redacted fragment.
public void addRedactionAnnotation(Page page, Rectangle rectangle, String overlayText, String colorHex) {
var annotation = new RedactionAnnotation(page, rectangle);
var color = hexToColor(colorHex);
annotation.setFillColor(color);
annotation.setColor(Color.getBlack());
annotation.setModified(new Date());
annotation.setOverlayText(overlayText);
annotation.setTextAlignment(HorizontalAlignment.Left);
annotation.setRepeat(false);
annotation.redact();
page.getAnnotations().add(annotation);
}
Input pdf: 1524.pdf (199.6 KB)
Result pdf: RedactionAssembleTest.pdf (262.3 KB)
Redactions:
- “nonserious adverse event”,
rectangle:(293.44815186174,517.708540237434,379.764570365906,526.141140388497)
,
"value" : "nonserious adverse event", "startPage" : 1, "endPage" : 1, "tokens" : [ { "pageNumber" : 1, "tokenIndex" : 137, "positionIndex" : 136 }, { "pageNumber" : 1, "tokenIndex" : 138, "positionIndex" : 137 }, { "pageNumber" : 1, "tokenIndex" : 139, "positionIndex" : 138 } ]
- “atopic dermatics”,
rectangle:(360.777740534378,567.03854041291,418.142386535645,575.471140563973)
,
"value" : "atopic dermatics", "startPage" : 1, "endPage" : 1, "tokens" : [ { "pageNumber" : 1, "tokenIndex" : 67, "positionIndex" : 67 }, { "pageNumber" : 1, "tokenIndex" : 68, "positionIndex" : 68 } ]