mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Add a default DA for textfield to avoid issues when printing or saving
* it aims to fix issue #12750
This commit is contained in:
parent
c366390f6b
commit
a7c682c600
4 changed files with 26 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue