pdf-lite 1.7.2 → 1.7.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -100,9 +100,20 @@ export class PdfNumberToken extends PdfToken {
|
|
|
100
100
|
return value.toBytes();
|
|
101
101
|
}
|
|
102
102
|
const numberValue = value instanceof Ref ? value.resolve() : value;
|
|
103
|
-
|
|
103
|
+
let valueString = decimalPlaces
|
|
104
104
|
? numberValue.toFixed(decimalPlaces)
|
|
105
105
|
: numberValue.toString();
|
|
106
|
+
// toFixed() always adds a leading zero (e.g. 0.5), but the original PDF
|
|
107
|
+
// may have omitted it (e.g. .5). If padTo is set and the formatted string
|
|
108
|
+
// is longer than padTo, strip the leading zero to match the original length.
|
|
109
|
+
if (padTo !== undefined && valueString.length > padTo) {
|
|
110
|
+
if (valueString.startsWith('0.')) {
|
|
111
|
+
valueString = valueString.slice(1);
|
|
112
|
+
}
|
|
113
|
+
else if (valueString.startsWith('-0.')) {
|
|
114
|
+
valueString = '-' + valueString.slice(2);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
106
117
|
const tokenString = valueString.padStart(padTo ?? 0, '0');
|
|
107
118
|
return stringToBytes(tokenString);
|
|
108
119
|
}
|