Skip to content

Fix: Ensure PdfForm is returned even when acroForm has no fields #2333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tungthanh1497
Copy link

Summary

This pull request fixes an issue in the PdfDocument.form getter where the form would not be returned if the acroForm existed in the catalog but contained no fields (fields.count == 0).

As a result, _form would remain null, leading to inconsistent behavior or potential null access elsewhere in the code.

What was changed

  • Moved the return statement outside the if (_form!.fields.count != 0) condition.
  • Ensured _form is always returned once initialized, regardless of the number of fields.

Why is this needed?

In some PDF documents, the acroForm dictionary exists but does not yet have any form fields (e.g., newly created or partially filled forms). Without this fix, attempting to access form would result in a null, which may cause exceptions or unexpected behavior in consumer code.

How to test

  • Open a PDF document with an empty acroForm dictionary.
  • Call document.form and ensure it returns a valid PdfForm instance, not null.
  • Ensure no exceptions are thrown during the access.

@VijayakumarMariappan VijayakumarMariappan added pdf PDF component open Open labels Apr 16, 2025
@SF2381
Copy link

SF2381 commented Apr 22, 2025

Hi @tungthanh1497 ,

Thank you for the information. We are currently working on this issue and plan to include the fix in our upcoming release, which is expected to be available on April 29, 2025.

With regards,
Anand P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open Open pdf PDF component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants