Skip to content

Conversation

Ajaypanchal4326
Copy link

Fixes :

This PR fixes issue #20214 where PDF form calculation fields display repeating digit patterns (e.g., "37037037" instead of "3" or "37.037.03" instead of "3") when calculated values are processed incorrectly by the PDF.js JavaScript engine.

Problem :

When users fill out PDF forms with calculated fields (like mean scores), the calculation results sometimes show malformed repeating patterns:

"37037037" instead of "37"
"37.037.03" instead of "3"
"333333" instead of "3"

This occurs when PDF calculation scripts run incorrectly in PDF.js JavaScript environment, causing string concatenation instead of proper numeric calculation.

Screenshot 2025-08-30 152456

Root Cause :

The issue stems from:

  1. PDF calculation scripts producing malformed string results
  2. The WidgetAnnotation constructor not detecting these calculation errors
  3. Malformed strings being converted to numbers without validation

Solution :

Enhanced the WidgetAnnotation constructor's value processing logic
Added _fixRepeatingCalculationValue() method to detect and correct malformed calculation results
Implemented pattern detection for various types of calculation errors
Added comprehensive logging for debugging
Maintains full backward compatibility

Screenshot 2025-09-01 132802

Files Changed :

  • src/core/annotation.js - Enhanced WidgetAnnotation value processing
  • test/unit/annotation_spec.js - Added comprehensive test coverage

decodedValue = decodedValue[0];
}

class WidgetAnnotation extends Annotation {
Copy link
Contributor

@timvandermeij timvandermeij Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this class repeated inside the class with the exact same name and same of the exact same code? Does that actually work?

yarn.lock Outdated
@@ -0,0 +1,6507 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be removed; it's unrelated to the patch.

data.fieldValue = decodedValue;
}
/**
* Fix calculation values that show repeating patterns due to JavaScript execution errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit arbitrary to me. How do we know for sure that the repeated value wasn't intended by the user? Is there anything in the PDF specification that explains how to deal with this situation?

@timvandermeij
Copy link
Contributor

Please make sure the commits are squashed into one, and ensure that that commit has a good commit message that explains the issue and the approach for fixing it in a concise manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants