ArgumentNullException when applying redactions to specific PDF documents using Aspose.PDF

ArgumentNullException when applying redactions to specific PDF documents using Aspose.PDF

Issue Description

We are encountering an ArgumentNullException when attempting to apply redactions to certain PDF documents using Aspose.PDF. The error occurs when calling PdfAnnotationEditor.RedactArea() to place colored rectangles over sensitive content. This issue only affects specific documents, while the same redaction code works correctly on other PDFs.

Error Details

System.ArgumentNullException: Value cannot be null. (Parameter 'decoder')
   at #=zW2gMBQoih81grQ5I13D67w5y2kzjZuqQbdBECt0=.#=zUL9Ge84=(#=zhlAHOKFMXUpXPitDAqLmG5wEnK4KjDxYRg== #=zx5ECaBs=, #=zfLChRnFaOwh0_ghz_2KD$4y8elLRY9AGhw== #=zxNtNQUQ=, Stream #=zmL_ezBk=)
   at Aspose.Pdf.XImageCollection.#=zS1A8zcpFcHIY(TiffImage #=z7qa7jUZ2Fhdw, #=zKfXWnqjLNuAAZaYA4K19WrF8jIAH0iY$FQ== #=zEdmfPlA=, TiffCompressions #=z7ZmCA8Y=, Byte[] #=zdkpe4BA=)
   at #=z5XuTd4bCWKlEzHS0xZvZK7L6gPrnFTN1IA==.#=zZwJQDS1H2Mvy$A1jpg==(Page #=zWvFv8KQ=, Rectangle #=zUf9JZuA=, Color #=ztiQaJSA=)
   at Aspose.Pdf.Facades.PdfAnnotationEditor.RedactArea(Int32 pageIndex, Rectangle rect, Color color)
   at OurApplication.ApplyRedactionBox(Rectangle rectangle, Color color)
   at OurApplication.ApplyTextRedaction(BoundingBox bounds, String text)
   at OurApplication.ProcessRedactions(Document document, List<Redaction> redactions)

Context

  • Aspose.PDF Version: 25.8.0
  • Target Framework: .NET 6.0
  • Environment: Windows

Observations

  1. The error appears to be related to a null ‘decoder’ parameter within Aspose.PDF’s internal image processing code
  2. The stack trace suggests the issue occurs when the library attempts to handle TIFF images or image collections during the redaction process
  3. This error only occurs with specific PDF documents - the same code works correctly with other PDFs
  4. The error happens when calling PdfAnnotationEditor.RedactArea() method
  5. Failed redactions typically occur on the first redaction attempt on the first page of affected documents
  6. The redaction process involves placing solid color rectangles over text areas to obscure sensitive information

Code Sample

Here’s a simplified version of how we’re applying redactions:

using Aspose.Pdf;
using Aspose.Pdf.Facades;
using System.Drawing;

public class PdfRedactionService
{
    private PdfAnnotationEditor annotationEditor;
    private Document pdfDocument;
    
    public void ApplyRedactions(string inputPath, List<RedactionArea> redactions)
    {
        pdfDocument = new Document(inputPath);
        annotationEditor = new PdfAnnotationEditor();
        annotationEditor.BindPdf(pdfDocument);
        
        foreach (var redaction in redactions)
        {
            // Convert our coordinates to Aspose Rectangle
            var rect = new Aspose.Pdf.Rectangle(
                redaction.X1, 
                redaction.Y1, 
                redaction.X2, 
                redaction.Y2
            );
            
            // This is where the ArgumentNullException occurs for specific PDFs
            annotationEditor.RedactArea(
                redaction.PageIndex, 
                rect, 
                Color.Black  // Using black color to cover the content
            );
        }
        
        annotationEditor.Save(outputPath);
    }
}

public class RedactionArea
{
    public int PageIndex { get; set; }
    public double X1 { get; set; }
    public double Y1 { get; set; }
    public double X2 { get; set; }
    public double Y2 { get; set; }
}

Questions

  1. What could cause the ‘decoder’ parameter to be null in this specific scenario?
  2. Are there known issues with certain PDF types or embedded image formats that could trigger this error?
  3. Is there a way to detect problematic PDFs before attempting redaction to implement a workaround?
  4. Are there any specific PDF properties or embedded content types we should check for that might cause this issue?
  5. Could this be related to specific TIFF compression types or image formats within the PDF?
  6. Is there a recommended way to pre-process or validate PDFs before applying redactions?

Additional Information

  • The affected documents appear to contain embedded images or specific formatting that triggers this error
  • The error seems to occur during the image processing/decoding phase of the redaction operation
  • The same coordinates and color parameters work fine on other PDFs
  • We can provide sample PDFs that reproduce this issue if needed (with appropriate confidentiality agreements)
  • The error is consistent and reproducible with the affected documents

Any insights into what might cause this ArgumentNullException and how to resolve it would be greatly appreciated. We’re happy to provide additional information or test files if that would help diagnose the issue.

Thank you for your assistance!

@JamRel

Have you tried using the latest version i.e. 25.11 and if issue still persists, we request you please share your sample PDF document with us so that we can create an investigation ticket in our issue tracking system to address it and share the ID with you.