1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #12751 from calixteman/da_not_a_string

Add a default DA for textfield to avoid issues when printing or saving
This commit is contained in:
Brendan Dahl 2020-12-21 09:44:08 -08:00 committed by GitHub
commit 3ea1c43b15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 1 deletions

View file

@ -984,10 +984,13 @@ class WidgetAnnotation extends Annotation {
data.defaultFieldValue = this._decodeFormValue(defaultFieldValue);
data.alternativeText = stringToPDFString(dict.get("TU") || "");
data.defaultAppearance =
const defaultAppearance =
getInheritableProperty({ dict, key: "DA" }) ||
params.acroForm.get("DA") ||
"";
data.defaultAppearance = isString(defaultAppearance)
? defaultAppearance
: "";
const fieldType = getInheritableProperty({ dict, key: "FT" });
data.fieldType = isName(fieldType) ? fieldType.name : null;
@ -1272,6 +1275,15 @@ class WidgetAnnotation extends Annotation {
const totalHeight = this.data.rect[3] - this.data.rect[1];
const totalWidth = this.data.rect[2] - this.data.rect[0];
if (!this.data.defaultAppearance) {
// The DA is required and must be a string.
// If there is no font named Helvetica in the resource dictionary,
// the evaluator will fall back to a default font.
// Doing so prevents exceptions and allows saving/printing
// the file as expected.
this.data.defaultAppearance = "/Helvetica 0 Tf 0 g";
}
const fontInfo = await this._getFontData(evaluator, task);
const [font, fontName] = fontInfo;
const fontSize = this._computeFontSize(...fontInfo, totalHeight);