Skip to content

Commit

Permalink
stephanrauh/ngx-extended-pdf-viewer#1887 include the form values pass…
Browse files Browse the repository at this point in the history
…ed 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
  • Loading branch information
stephanrauh committed Oct 17, 2023
1 parent 6d31935 commit a6163a2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
61 changes: 38 additions & 23 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,12 +1157,16 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
// NOTE: We cannot set the values using `element.value` below, since it
// prevents the AnnotationLayer rasterizer in `test/driver.js`
// from parsing the elements correctly for the reference tests.
// #1737 modified by ngx-extended-pdf-viewer
// #1737 + #1887 modified by ngx-extended-pdf-viewer
const angularData = window.getFormValueFromAngular(this.data.fieldName);
const storedData = angularData.value ? angularData : storage.getValue(id, {
const formData = storage.getValue(id, {
value: this.data.fieldValue
});
// #1737 end of modification by ngx-extended-pdf-viewer
const storedData = angularData.value ? angularData : formData;
if (angularData !== formData) {
storage.setValue(id, { value: angularData.value });
}
// #1737 + #1887 end of modification by ngx-extended-pdf-viewer
let textContent = storedData.value || "";
const maxLen = storage.getValue(id, {
charLimit: this.data.maxLen,
Expand Down Expand Up @@ -1507,25 +1511,27 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
const data = this.data;
const id = data.id;

// #1737 modified by ngx-extended-pdf-viewer
// #1737, #1887 modified by ngx-extended-pdf-viewer
const angularData = window.getFormValueFromAngular(this.data.fieldName);
const formValue = storage.getValue(id, {
value: data.exportValue === data.fieldValue,
}).value;
let angularValue = undefined;
if (angularData.value) {
angularValue = angularData.value === true || angularData.value === data.exportValue;
}
let value =
angularValue !== undefined
? angularValue
: storage.getValue(id, {
value: data.exportValue === data.fieldValue,
}).value;
// #1737 end of modification by ngx-extended-pdf-viewer
if (typeof value === "string") {
: formValue;
// #1737, #1887 end of modification by ngx-extended-pdf-viewer
let updateAngularValueNecessary = false;
if (typeof value === "string" || angularData !== formValue) {
// The value has been changed through js and set in annotationStorage.
value = value !== "Off";
storage.setValue(id, { value });
// #1737 modified by ngx-extended-pdf-viewer
window.updateAngularFormValue(id, { value });
updateAngularValueNecessary = true;
// #1737 end of modification by ngx-extended-pdf-viewer
}

Expand Down Expand Up @@ -1571,7 +1577,12 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
// #1737 modified by ngx-extended-pdf-viewer
window.registerAcroformField(id, element, value ? data.exportValue : false);
element.addEventListener("updateFromAngular", newvalue => storage.setValue(id, { value: newvalue.detail }));
// #1737 end of modification by ngx-extended-pdf-viewer
// #1887 end of modification by ngx-extended-pdf-viewer
if (updateAngularValueNecessary) {
window.updateAngularFormValue(id, { value });
}
// #1887 end of modification by ngx-extended-pdf-viewer

if (this.enableScripting && this.hasJSActions) {
element.addEventListener("updatefromsandbox", jsEvent => {
const actions = {
Expand Down Expand Up @@ -1620,22 +1631,22 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
const storage = this.annotationStorage;
const data = this.data;
const id = data.id;
// #1737 modified by ngx-extended-pdf-viewer
// #1737, #1887 modified by ngx-extended-pdf-viewer
const angularData = window.getFormValueFromAngular(this.data.fieldName);

const formValue = storage.getValue(id, {
value: data.fieldValue === data.buttonValue,
}).value;
let value =
angularData.value ??
storage.getValue(id, {
value: data.fieldValue === data.buttonValue,
}).value;
if (typeof value === "string") {
formValue;
if (typeof value === "string" || angularData !== formValue) {
// The value has been changed through js and set in annotationStorage.
value = value === data.buttonValue; // TODO: this line in pdf.js seems to be buggy
storage.setValue(id, { value });
} else if (value) {
window.updateAngularFormValue(id, { value: data.buttonValue });
}
// #1737 end of modification by ngx-extended-pdf-viewer
// #1737, #1887 end of modification by ngx-extended-pdf-viewer

const element = document.createElement("input");
GetElementsByNameSet.add(element);
Expand Down Expand Up @@ -1760,15 +1771,19 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
const storage = this.annotationStorage;
const id = this.data.id;

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

const formData = storage.getValue(id, {
value: this.data.fieldValue,
});
const storedData = angularData.value
? angularData
: storage.getValue(id, {
value: this.data.fieldValue,
});
// #1737 end of modification by ngx-extended-pdf-viewer
: formData;
if (angularData !== formData) {
storage.setValue(id, { value: angularData.value });
}
// #1737, #1887 end of modification by ngx-extended-pdf-viewer

const selectElement = document.createElement("select");
GetElementsByNameSet.add(selectElement);
Expand Down
5 changes: 4 additions & 1 deletion web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ class AnnotationLayerBuilder {
if (!this.div) {
return;
}
this.div.hidden = true;
// #1887 modified by ngx-extended-pdf-viewer
if (!document.querySelector("[data-pdfjsprinting=true]")) {
this.div.hidden = true;
}
}

#updatePresentationModeState(state) {
Expand Down
2 changes: 1 addition & 1 deletion web/ngx-extended-pdf-viewer-version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const ngxExtendedPdfViewerVersion = '18.0.0-beta.9';
export const ngxExtendedPdfViewerVersion = '18.1.1';

0 comments on commit a6163a2

Please sign in to comment.