fix: flatten form fields for fillable PDFs without appearance streams (#240)#242
Merged
fix: flatten form fields for fillable PDFs without appearance streams (#240)#242
Conversation
…eams (#240) init_forms() alone is insufficient for fillable PDFs that lack pre-generated appearance streams for form fields (common in government forms like VA-21-22a). page.flatten() forces PDFium to generate appearances and merge them into page content before rendering, ensuring all form field values are visible. Changes: - ocr/service.py: add page.flatten() before _extract_page_image() in rendering loop - bda_processresults_function/index.py: add page.flatten() before render() - test_ocr_service.py: verify both init_forms() and flatten() are called - CHANGELOG.md: update fix description with two-part explanation
8a43f85 to
f79f8e5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to PR #241. The initial fix (
init_forms()only) was insufficient — fillable PDFs that lack pre-generated appearance streams still rendered without form field values.Root Cause (Refined)
init_forms()initializes PDFium's form rendering engine, butrender(may_draw_forms=True)can only draw form fields that have appearance streams. Many fillable PDFs — especially government forms like VA Form 21-22a — don't include appearance streams for their form fields. They rely on the PDF viewer to generate them at runtime.Fix
Added
page.flatten()before eachpage.render()call:init_forms()— initializes the form engine (already in develop from PR fix: initialize form rendering for fillable PDFs (#240) #241)page.flatten()— NEW: forces PDFium to generate appearance streams and merge form field content into the page, making it visible torender()Changes
lib/idp_common_pkg/idp_common/ocr/service.py— Addedpage.flatten()in the rendering loop before_extract_page_image()patterns/unified/src/bda_processresults_function/index.py— Addedpage.flatten()beforepage.render()lib/idp_common_pkg/tests/unit/ocr/test_ocr_service.py— Updated regression test to verify bothinit_forms()andflatten()CHANGELOG.md— Updated fix descriptionRisk Assessment
flatten()is a no-op for pages without form fields (returns immediately)