Skip to content

fix: guard page.flatten() for non-fillable PDFs (#240)#243

Merged
rstrahan merged 4 commits intodevelopfrom
fix/pdf-ocr
Mar 18, 2026
Merged

fix: guard page.flatten() for non-fillable PDFs (#240)#243
rstrahan merged 4 commits intodevelopfrom
fix/pdf-ocr

Conversation

@rstrahan
Copy link
Copy Markdown
Contributor

Fixes the regression where page.flatten() crashes for regular (non-fillable) PDFs.

Root cause: flatten() requires page.formenv to be non-None, but for PDFs without AcroForm fields, init_forms() sets formenv = None (no form data to initialize). The unconditional page.flatten() then fails.

Fix: Guard with if page.formenv is not None: before calling flatten(). This ensures:

  • ✅ Fillable PDFs: flatten() is called (formenv is set)
  • ✅ Regular PDFs: flatten() is skipped (formenv is None)

Verified locally with both samples/lending_package.pdf (regular) and fillable VA forms.

Bob Strahan added 4 commits March 18, 2026 12:17
page.flatten() requires formenv to be set, which only happens for PDFs
with AcroForm fields. For regular PDFs without forms, formenv is None
and flatten() raises an error. Added conditional guard to only call
flatten() when page.formenv is not None.
- Changed 'img_bytes = None' to 'del img_bytes' to fix reportAssignmentType
  type error (None not assignable to bytes parameter)
- Added PEP 440 version validation to 'make version' using packaging.version
@rstrahan rstrahan merged commit dff64a3 into develop Mar 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant