Add a default DA for textfield to avoid issues when printing or saving

* it aims to fix issue #12750
This commit is contained in:
Calixte Denizet 2020-12-18 13:17:23 +01:00
parent c366390f6b
commit a7c682c600
4 changed files with 26 additions and 1 deletions

View File

@ -994,10 +994,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;
@ -1282,6 +1285,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);

View File

@ -48,6 +48,7 @@
!issue6931_reduced.pdf
!issue7580.pdf
!issue7598.pdf
!issue12750.pdf
!issue7665.pdf
!issue7696.pdf
!issue7835.pdf

BIN
test/pdfs/issue12750.pdf Normal file

Binary file not shown.

View File

@ -2779,6 +2779,18 @@
"link": true,
"type": "eq"
},
{ "id": "issue12750",
"file": "pdfs/issue12750.pdf",
"md5": "47a39ef5d6ae2e4f52887c477cfdfc9e",
"rounds": 1,
"type": "eq",
"print": true,
"annotationStorage": {
"12R": {
"value": "foobar"
}
}
},
{ "id": "preistabelle-text",
"file": "pdfs/preistabelle.pdf",
"md5": "d2f0b2086160d4f3d325c79a5dc1fb4d",