Redactions Cause Text Shift If Words Are Different Colours

While messing around with redactions I noticed a bit of an issue happening when redacting a sentence with multiple word formats/colours. If the last word in a redaction box has a different colour to the first word after the redaction box, all of the text after the redaction on the same line will shift. This can be recreated very easily on Word documents and Emails that are converted to a PDF before redacting.

This is the document before the redactions :

Before_Redactions.png (20.6 KB)

This is the document after redactions :

After_Redactions.png (3.6 KB)

As you can see, the first three lines where the final word in the redaction box is a different colour to the first word outside the redaction, the text shifts to the start of the line and ends up being behind the redaction box while still physically on the page. The final two lines were unaffected because the formatting on the last word in the redaction was not different to the next word.

This is the code currently being used :

   public void ConvertAndRedactDoc(string filePath)
   {
       var doc = new Aspose.Words.Document(filePath);

       var saveOptions = new Aspose.Words.Saving.PdfSaveOptions
       {
           PreserveFormFields = true,
           TextCompression = Aspose.Words.Saving.PdfTextCompression.None,
           ExportDocumentStructure = true,
           UseCoreFonts = false,
           SaveFormat = SaveFormat.Pdf
       };

       var convertedFilePath = filePath.Replace($".docx", "-CONVERTED.pdf");

       doc.Save(convertedFilePath, saveOptions);

       RedactDocument(convertedFilePath);
   }


   public void RedactDocument(string filePath)
   {
       Document doc = new Document(filePath);


       foreach (var page in doc.Pages)
       {
           var redactions = new List<Rectangle>()
           {
               new Rectangle(69.823577769806533, 733.151603806142, 228.90616217318021, 759.07837957924721),
               new Rectangle(70.543408468464335, 696.422004794243, 218.828532391971, 716.58727483999144),
               new Rectangle(68.383916372490944, 649.60977075946971, 161.96190719800487, 679.8576758280924),
               new Rectangle(69.103747071148746, 612.88017174757056, 172.75936767787184, 639.52713573659537),
               new Rectangle(71.263239167122137, 573.99000808791277, 172.75936767787184, 598.47640742917883)
           };
           
           redactions.ForEach(redactionRect =>
           {
               var redactionAnno = new RedactionAnnotation(doc.Pages[page.Number], redactionRect);
               redactionAnno.FillColor = Color.Black;
               doc.Pages[page.Number].Annotations.Add(redactionAnno, true);
               redactionAnno.Redact();
           });
       }

       doc.Save(filePath.Replace($".pdf", "-REDACTED.pdf"));
   }

This is the document used in the tests :

Aspose Test Document.docx (13.4 KB)

@DomTheDev

Can you please confirm you are using the latest versions of the APIs? Also, would you please share the generated final document with us as well? We will test the scenario in our environment and address it accordingly.

Hi, here is the final document with the redaction issues :
Aspose Test Document-CONVERTED-REDACTED.pdf (45.3 KB)

I was using v23.2.0 when I initially found the issue but I can confirm that I can replicate it in the latest versions (v25.6.0)

@DomTheDev

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-60088

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.