Incompatibility betwen versions 25.10.00 and 25.12.00 (textabsorbers works different)

Aspose.PDF 25.12.0 — TextAbsorber throws ArgumentNullException on Form XObjects without /Resources (regression vs 25.10.0)

Summary

Aspose.Pdf.Text.TextAbsorber.Visit(Page) throws an unhandled System.ArgumentNullException: Value cannot be null. (Parameter 'collection') when extracting text from a page that contains /Form XObjects with no /Resources dictionary — a structure that is valid per the PDF specification when the form doesn’t reference any font/image/pattern.

This is a regression: the exact same file, opened with Aspose.PDF 25.10.0, extracts text from every page without error. With Aspose.PDF 25.12.0, extraction fails.

Environment

  • Failing version: Aspose.PDF for .NET 25.12.0
  • Working version (same file, same code): Aspose.PDF for .NET 25.10.0
  • Target framework: .NET 8.0, Windows
  • License: [indicar aquí vuestro tipo de licencia/trial]

Error

System.ArgumentNullException: Value cannot be null. (Parameter 'collection')
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at Aspose.Pdf.Text.TextAbsorber.Visit(Page page)
   at Aspose.Pdf.Page.Accept(TextAbsorber visitor)

Method that fails: Aspose.Pdf.Text.TextAbsorber.Visit(Page page), invoked via Aspose.Pdf.Page.Accept(TextAbsorber visitor).

Minimal Reproduction

using Aspose.Pdf;
using Aspose.Pdf.Text;

using var document = new Document("Hoja de Salario.pdf"); // attached to this ticket
Console.WriteLine($"Aspose.Pdf assembly version: {typeof(Document).Assembly.GetName().Version}");
Console.WriteLine($"Page count: {document.Pages.Count}");

for (int i = 1; i <= document.Pages.Count; i++)
{
    var page = document.Pages[i];
    try
    {
        var absorber = new TextAbsorber();
        page.Accept(absorber);
        Console.WriteLine($"Page {i}: OK ({absorber.Text.Length} chars)");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Page {i}: FAILED -> {ex.GetType().Name}: {ex.Message}");
    }
}

Result with Aspose.PDF 25.12.0

Page 1: OK (6429 chars)
Page 2: OK (6440 chars)
Page 3: FAILED -> ArgumentNullException: Value cannot be null. (Parameter 'collection')

Result with Aspose.PDF 25.10.0 (same file, same code)

Page 1: OK (6429 chars)
Page 2: OK (6440 chars)
Page 3: OK (6439 chars)

Root Cause Analysis

We inspected the failing page’s resource tree directly:

Page 3: Contents.Count = 3562, Resources.Fonts.Count = 1, Resources.Images.Count = 0
Resources.Forms.Count = 16
  Form #1  : Resources == null; Contents.Count = 5
  Form #2  : Resources == null; Contents.Count = 177
  Form #3  : Resources != null; Contents.Count = 24  (Fonts.Count = 1)
  Form #4  : Resources != null; Contents.Count = 15  (Fonts.Count = 1)
  Form #5  : Resources != null; Contents.Count = 15  (Fonts.Count = 1)
  Form #6  : Resources != null; Contents.Count = 15  (Fonts.Count = 1)
  Form #7  : Resources != null; Contents.Count = 30  (Fonts.Count = 1)
  Form #8  : Resources == null; Contents.Count = 24
  Form #9  : Resources == null; Contents.Count = 5
  Form #10 : Resources == null; Contents.Count = 5
  Form #11 : Resources == null; Contents.Count = 5
  Form #12 : Resources == null; Contents.Count = 5
  Form #13 : Resources == null; Contents.Count = 5
  Form #14 : Resources == null; Contents.Count = 5
  Form #15 : Resources == null; Contents.Count = 0
  Form #16 : Resources == null; Contents.Count = 177
Annotations.Count = 0

10 of the 16 Form XObjects on this page have no /Resources entry at all (they only draw vector graphics — lines/rectangles — and don’t reference any font or image, so omitting /Resources is valid per the PDF spec). Aspose.PDF 25.12.0’s TextAbsorber does not null-check the resources of these Form XObjects before merging/aggregating them (looks like an internal resources.SomeCollection.AddRange(...) call without a null guard when recursing into a Form XObject). Aspose.PDF 25.10.0 handles the exact same structure without any issue.

We also confirmed document.Pages[3].Resources (the page-level resources) is not null and has a valid Fonts collection — only the nested Form XObjects are missing /Resources.

Impact

Breaks text extraction (TextAbsorber) for any PDF containing Form XObjects without an explicit /Resources dictionary — valid PDF structure that was silently tolerated in 25.10.0.

Requested Action

  1. Confirm this as a regression introduced between 25.10.0 and 25.12.0 in TextAbsorber’s handling of Form XObjects with a null/missing /Resources dictionary.
  2. Provide a fix or patched build that null-checks the resource collection before recursing/aggregating on Form XObjects.
  3. Confirm whether there is any supported public API to assign/repair an empty Resources object on an existing XForm instance — we found XForm.Resources has no public setter, so we cannot sanitize affected documents from our own code as a workaround.

Attachments

  • Minimal repro console project (.csproj + Program.cs above).
  • The affected PDF file (page 3 reproduces the issue) — attached separately.

@ramon.gonzalez
Could you attach the mentioned sample file, please?
Also could you confirm that the issue is still reproducible on latest version of Aspose PDF (currently it’s 26.9)?