InvalidOperationException when redacting PDF with flattened stamps

We are hitting an InvalidOperationException: Stack empty error when attempting to place two redactions on the attached document after flattening the stamp annotations.

This happens with both PdfAnnotationEditor.RedactArea and RedactionAnnotation, Redact.

It only happens when applying the redactions in the order below. Also, the second rectangle can be redacted alone with no error. It only errors if rectangle 1 is already redacted.

We are using Aspose.PDF.Drawing 26.3.0, and I have verified it is still happening in 26.6.0.

Reproduction code:

using var stream = File.OpenRead([document location]);
using var document = new Document(stream);
var stampAnnotations = document.Pages[1].Annotations
	.Where(x => x.AnnotationType == AnnotationType.Stamp).ToList();
foreach (var annotation in stampAnnotations)
	{
		annotation.Flatten();
	}

var rectangle1 = new Rectangle(371, 17, 587, 155);
var rectangle2 = new Rectangle(350, 173, 418, 221);

Both of these redaction paths fail with the same error:

using var editor = new PdfAnnotationEditor(document);
editor.RedactArea(1, rectangle1, System.Drawing.Color.Black);
editor.RedactArea(1, rectangle2, System.Drawing.Color.Black);

And:

var redactionAnnotation1 = new RedactionAnnotation(document.Pages[1], rectangle1);
var redactionAnnotation2 = new RedactionAnnotation(document.Pages[1], rectangle2);
redactionAnnotation1.Redact();
redactionAnnotation2.Redact();

ManyStampsPDF-WithPPTStamp.pdf (839.8 KB)

Thank you for investigating.

1 Like

@lauramoon
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-62442

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.

Hi, I checked and reproduced the issue, thank you for providing info.
You’ll be notified when issue will be resolved