Skip to content

Commit a6163a2

Browse files
committed
stephanrauh/ngx-extended-pdf-viewer#1887 include the form values passed by [formData] in printed and downloaded PDF files; stop hiding the annotation layer when the print window shows
mozilla#1887 include the form values passed by [formData] in printed and downloaded PDF files; stop hiding the annotation layer when the print window shows
1 parent 6d31935 commit a6163a2

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

src/display/annotation_layer.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,12 +1157,16 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
11571157
// NOTE: We cannot set the values using `element.value` below, since it
11581158
// prevents the AnnotationLayer rasterizer in `test/driver.js`
11591159
// from parsing the elements correctly for the reference tests.
1160-
// #1737 modified by ngx-extended-pdf-viewer
1160+
// #1737 + #1887 modified by ngx-extended-pdf-viewer
11611161
const angularData = window.getFormValueFromAngular(this.data.fieldName);
1162-
const storedData = angularData.value ? angularData : storage.getValue(id, {
1162+
const formData = storage.getValue(id, {
11631163
value: this.data.fieldValue
11641164
});
1165-
// #1737 end of modification by ngx-extended-pdf-viewer
1165+
const storedData = angularData.value ? angularData : formData;
1166+
if (angularData !== formData) {
1167+
storage.setValue(id, { value: angularData.value });
1168+
}
1169+
// #1737 + #1887 end of modification by ngx-extended-pdf-viewer
11661170
let textContent = storedData.value || "";
11671171
const maxLen = storage.getValue(id, {
11681172
charLimit: this.data.maxLen,
@@ -1507,25 +1511,27 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
15071511
const data = this.data;
15081512
const id = data.id;
15091513

1510-
// #1737 modified by ngx-extended-pdf-viewer
1514+
// #1737, #1887 modified by ngx-extended-pdf-viewer
15111515
const angularData = window.getFormValueFromAngular(this.data.fieldName);
1516+
const formValue = storage.getValue(id, {
1517+
value: data.exportValue === data.fieldValue,
1518+
}).value;
15121519
let angularValue = undefined;
15131520
if (angularData.value) {
15141521
angularValue = angularData.value === true || angularData.value === data.exportValue;
15151522
}
15161523
let value =
15171524
angularValue !== undefined
15181525
? angularValue
1519-
: storage.getValue(id, {
1520-
value: data.exportValue === data.fieldValue,
1521-
}).value;
1522-
// #1737 end of modification by ngx-extended-pdf-viewer
1523-
if (typeof value === "string") {
1526+
: formValue;
1527+
// #1737, #1887 end of modification by ngx-extended-pdf-viewer
1528+
let updateAngularValueNecessary = false;
1529+
if (typeof value === "string" || angularData !== formValue) {
15241530
// The value has been changed through js and set in annotationStorage.
15251531
value = value !== "Off";
15261532
storage.setValue(id, { value });
15271533
// #1737 modified by ngx-extended-pdf-viewer
1528-
window.updateAngularFormValue(id, { value });
1534+
updateAngularValueNecessary = true;
15291535
// #1737 end of modification by ngx-extended-pdf-viewer
15301536
}
15311537

@@ -1571,7 +1577,12 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
15711577
// #1737 modified by ngx-extended-pdf-viewer
15721578
window.registerAcroformField(id, element, value ? data.exportValue : false);
15731579
element.addEventListener("updateFromAngular", newvalue => storage.setValue(id, { value: newvalue.detail }));
1574-
// #1737 end of modification by ngx-extended-pdf-viewer
1580+
// #1887 end of modification by ngx-extended-pdf-viewer
1581+
if (updateAngularValueNecessary) {
1582+
window.updateAngularFormValue(id, { value });
1583+
}
1584+
// #1887 end of modification by ngx-extended-pdf-viewer
1585+
15751586
if (this.enableScripting && this.hasJSActions) {
15761587
element.addEventListener("updatefromsandbox", jsEvent => {
15771588
const actions = {
@@ -1620,22 +1631,22 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
16201631
const storage = this.annotationStorage;
16211632
const data = this.data;
16221633
const id = data.id;
1623-
// #1737 modified by ngx-extended-pdf-viewer
1634+
// #1737, #1887 modified by ngx-extended-pdf-viewer
16241635
const angularData = window.getFormValueFromAngular(this.data.fieldName);
1625-
1636+
const formValue = storage.getValue(id, {
1637+
value: data.fieldValue === data.buttonValue,
1638+
}).value;
16261639
let value =
16271640
angularData.value ??
1628-
storage.getValue(id, {
1629-
value: data.fieldValue === data.buttonValue,
1630-
}).value;
1631-
if (typeof value === "string") {
1641+
formValue;
1642+
if (typeof value === "string" || angularData !== formValue) {
16321643
// The value has been changed through js and set in annotationStorage.
16331644
value = value === data.buttonValue; // TODO: this line in pdf.js seems to be buggy
16341645
storage.setValue(id, { value });
16351646
} else if (value) {
16361647
window.updateAngularFormValue(id, { value: data.buttonValue });
16371648
}
1638-
// #1737 end of modification by ngx-extended-pdf-viewer
1649+
// #1737, #1887 end of modification by ngx-extended-pdf-viewer
16391650

16401651
const element = document.createElement("input");
16411652
GetElementsByNameSet.add(element);
@@ -1760,15 +1771,19 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
17601771
const storage = this.annotationStorage;
17611772
const id = this.data.id;
17621773

1763-
// #1737 modified by ngx-extended-pdf-viewer
1774+
// #1737, #1887 modified by ngx-extended-pdf-viewer
17641775
const angularData = window.getFormValueFromAngular(this.data.fieldName);
17651776

1777+
const formData = storage.getValue(id, {
1778+
value: this.data.fieldValue,
1779+
});
17661780
const storedData = angularData.value
17671781
? angularData
1768-
: storage.getValue(id, {
1769-
value: this.data.fieldValue,
1770-
});
1771-
// #1737 end of modification by ngx-extended-pdf-viewer
1782+
: formData;
1783+
if (angularData !== formData) {
1784+
storage.setValue(id, { value: angularData.value });
1785+
}
1786+
// #1737, #1887 end of modification by ngx-extended-pdf-viewer
17721787

17731788
const selectElement = document.createElement("select");
17741789
GetElementsByNameSet.add(selectElement);

web/annotation_layer_builder.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ class AnnotationLayerBuilder {
178178
if (!this.div) {
179179
return;
180180
}
181-
this.div.hidden = true;
181+
// #1887 modified by ngx-extended-pdf-viewer
182+
if (!document.querySelector("[data-pdfjsprinting=true]")) {
183+
this.div.hidden = true;
184+
}
182185
}
183186

184187
#updatePresentationModeState(state) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const ngxExtendedPdfViewerVersion = '18.0.0-beta.9';
1+
export const ngxExtendedPdfViewerVersion = '18.1.1';

0 commit comments

Comments
 (0)