Spaces between words are removed in paragraph where redaction was done

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:

  1. “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 } ]
  2. “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 } ]

@valerijaslu

We were able to reproduce the similar issue in our environment while testing the scenario with Aspose.PDF for Java 21.11. Therefore, it has been logged as PDFJAVA-41062 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.