Skip to content

Use computed font height as font size#183

Closed
GooDer wants to merge 1 commit intoapache:trunkfrom
GooDer:fix-dynamic-form-field-font-size
Closed

Use computed font height as font size#183
GooDer wants to merge 1 commit intoapache:trunkfrom
GooDer:fix-dynamic-form-field-font-size

Conversation

@GooDer
Copy link
Copy Markdown

@GooDer GooDer commented Feb 6, 2024

Use computed font height as font size in case that form field has dynamic font size (0) and its value is empty so width can't be used

…amic font size (0) and its value is empty so width can't be used
@GooDer
Copy link
Copy Markdown
Author

GooDer commented Feb 6, 2024

Hello,

I have encounter problem during flattening of one of our PDF. I think that main reason of failure is wrong usage of form field in the source PDF but I can’t change it (I think it was generated by some tool). I can’t also shared the problematic PDF since it contains sensitive data.

During processing of flattening there is a method to calculate size of font for these dynamic form field and in this case it leads to division by zero float and ending as negative infinite.

It is edge case but still I think it would be good to handle it.

Element displayed in PDFBox debugger:
image

Values and place where problem happens in debugger:
image

I think that only height values should be taken into consideration in this case.

Used PDFBox 3.0.1, java 17

@THausherr
Copy link
Copy Markdown
Contributor

Thanks, I was able to reproduce this problem by using a very small rectangle width for the form field. I'm gonna fix this tomorrow.

asfgit pushed a commit that referenced this pull request Feb 7, 2024
@asfgit asfgit closed this in c192317 Feb 7, 2024
asfgit pushed a commit that referenced this pull request Feb 7, 2024
@THausherr
Copy link
Copy Markdown
Contributor

I committed a modified code that only checks for infinity because 1) it's more clear, 2) the method still returns a negative font size if the vertical size is negative, however this has no bad effect. I also added a test. Thanks for the report!

@GooDer GooDer deleted the fix-dynamic-form-field-font-size branch February 7, 2024 14:19
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.

2 participants