mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Add support for checkboxes printing
This commit is contained in:
parent
bf539deada
commit
cb60523a15
3 changed files with 164 additions and 15 deletions
|
@ -49,18 +49,21 @@ class AnnotationFactory {
|
|||
* instance.
|
||||
*/
|
||||
static create(xref, ref, pdfManager, idFactory) {
|
||||
return pdfManager.ensure(this, "_create", [
|
||||
xref,
|
||||
ref,
|
||||
pdfManager,
|
||||
idFactory,
|
||||
]);
|
||||
return pdfManager.ensureDoc("acroForm").then(acroForm => {
|
||||
return pdfManager.ensure(this, "_create", [
|
||||
xref,
|
||||
ref,
|
||||
pdfManager,
|
||||
idFactory,
|
||||
acroForm,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
static _create(xref, ref, pdfManager, idFactory) {
|
||||
static _create(xref, ref, pdfManager, idFactory, acroForm) {
|
||||
const dict = xref.fetchIfRef(ref);
|
||||
if (!isDict(dict)) {
|
||||
return undefined;
|
||||
|
@ -78,6 +81,7 @@ class AnnotationFactory {
|
|||
subtype,
|
||||
id,
|
||||
pdfManager,
|
||||
acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
|
||||
};
|
||||
|
||||
switch (subtype) {
|
||||
|
@ -514,8 +518,9 @@ class Annotation {
|
|||
return Promise.resolve(new OperatorList());
|
||||
}
|
||||
|
||||
const appearance = this.appearance;
|
||||
const data = this.data;
|
||||
const appearanceDict = this.appearance.dict;
|
||||
const appearanceDict = appearance.dict;
|
||||
const resourcesPromise = this.loadResources([
|
||||
"ExtGState",
|
||||
"ColorSpace",
|
||||
|
@ -533,14 +538,14 @@ class Annotation {
|
|||
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
|
||||
return evaluator
|
||||
.getOperatorList({
|
||||
stream: this.appearance,
|
||||
stream: appearance,
|
||||
task,
|
||||
resources,
|
||||
operatorList: opList,
|
||||
})
|
||||
.then(() => {
|
||||
opList.addOp(OPS.endAnnotation, []);
|
||||
this.appearance.reset();
|
||||
appearance.reset();
|
||||
return opList;
|
||||
});
|
||||
});
|
||||
|
@ -795,11 +800,16 @@ class WidgetAnnotation extends Annotation {
|
|||
getArray: true,
|
||||
});
|
||||
data.alternativeText = stringToPDFString(dict.get("TU") || "");
|
||||
data.defaultAppearance = getInheritableProperty({ dict, key: "DA" }) || "";
|
||||
data.defaultAppearance =
|
||||
getInheritableProperty({ dict, key: "DA" }) ||
|
||||
params.acroForm.get("DA") ||
|
||||
"";
|
||||
const fieldType = getInheritableProperty({ dict, key: "FT" });
|
||||
data.fieldType = isName(fieldType) ? fieldType.name : null;
|
||||
this.fieldResources =
|
||||
getInheritableProperty({ dict, key: "DR" }) || Dict.empty;
|
||||
getInheritableProperty({ dict, key: "DR" }) ||
|
||||
params.acroForm.get("DR") ||
|
||||
Dict.empty;
|
||||
|
||||
data.fieldFlags = getInheritableProperty({ dict, key: "Ff" });
|
||||
if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) {
|
||||
|
@ -961,6 +971,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||
constructor(params) {
|
||||
super(params);
|
||||
|
||||
this.checkedAppearance = null;
|
||||
this.uncheckedAppearance = null;
|
||||
|
||||
this.data.checkBox =
|
||||
!this.hasFieldFlag(AnnotationFieldFlag.RADIO) &&
|
||||
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
|
||||
|
@ -980,6 +993,40 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||
}
|
||||
}
|
||||
|
||||
getOperatorList(evaluator, task, renderForms, annotationStorage) {
|
||||
if (annotationStorage) {
|
||||
const value = annotationStorage[this.data.id] || false;
|
||||
let appearance;
|
||||
if (value) {
|
||||
appearance = this.checkedAppearance;
|
||||
} else {
|
||||
appearance = this.uncheckedAppearance;
|
||||
}
|
||||
|
||||
if (appearance) {
|
||||
const savedAppearance = this.appearance;
|
||||
this.appearance = appearance;
|
||||
const operatorList = super.getOperatorList(
|
||||
evaluator,
|
||||
task,
|
||||
renderForms,
|
||||
annotationStorage
|
||||
);
|
||||
this.appearance = savedAppearance;
|
||||
return operatorList;
|
||||
}
|
||||
|
||||
// No appearance
|
||||
return Promise.resolve(new OperatorList());
|
||||
}
|
||||
return super.getOperatorList(
|
||||
evaluator,
|
||||
task,
|
||||
renderForms,
|
||||
annotationStorage
|
||||
);
|
||||
}
|
||||
|
||||
_processCheckBox(params) {
|
||||
if (isName(this.data.fieldValue)) {
|
||||
this.data.fieldValue = this.data.fieldValue.name;
|
||||
|
@ -1003,6 +1050,14 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||
|
||||
this.data.exportValue =
|
||||
exportValues[0] === "Off" ? exportValues[1] : exportValues[0];
|
||||
|
||||
const normalAppearance = customAppearance.get("N");
|
||||
if (!isDict(normalAppearance)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.checkedAppearance = normalAppearance.get(this.data.exportValue);
|
||||
this.uncheckedAppearance = normalAppearance.get("Off") || null;
|
||||
}
|
||||
|
||||
_processRadioButton(params) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue