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.