1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[Acroform] Use the full path to find the node in the XFA datasets where to store the value

I noticed several 'Path not found' errors because of a field called #subform[2].
From the XFA specs, the hash is used for a class of elements in the template tree.
When we're looking for a node in the datasets tree, it doesn't make sense to search
for a class. Hence the path element starting with a hash are just skipped.
This commit is contained in:
Calixte Denizet 2023-02-22 22:08:21 +01:00
parent e676c9388d
commit 3a21423386
8 changed files with 135 additions and 5 deletions

View file

@ -1125,7 +1125,12 @@ class Annotation {
}
if (loopDict.has("T")) {
fieldName.unshift(stringToPDFString(loopDict.get("T")));
const t = stringToPDFString(loopDict.get("T"));
if (!t.startsWith("#")) {
// If it starts with a # then it's a class which is not a concept for
// datasets elements (https://www.pdfa.org/norm-refs/XFA-3_3.pdf#page=96).
fieldName.unshift(t);
}
}
}
return fieldName.join(".");
@ -1860,7 +1865,7 @@ class WidgetAnnotation extends Annotation {
}
const xfa = {
path: stringToPDFString(dict.get("T") || ""),
path: this.data.fieldName,
value,
};
@ -2787,7 +2792,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}
const xfa = {
path: stringToPDFString(dict.get("T") || ""),
path: this.data.fieldName,
value: value ? this.data.exportValue : "",
};
@ -2850,7 +2855,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}
const xfa = {
path: stringToPDFString(dict.get("T") || ""),
path: this.data.fieldName,
value: value ? this.data.buttonValue : "",
};

View file

@ -831,6 +831,13 @@ class WorkerMessageHandler {
setupDoc(docParams);
docParams = null; // we don't need docParams anymore -- saving memory.
});
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
handler.on("GetXFADatasets", function (data) {
return pdfManager.ensureDoc("xfaDatasets");
});
}
return workerHandlerName;
}

View file

@ -139,7 +139,12 @@ function writeXFADataForAcroform(str, newRefs) {
if (!path) {
continue;
}
const node = xml.documentElement.searchNode(parseXFAPath(path), 0);
const nodePath = parseXFAPath(path);
let node = xml.documentElement.searchNode(nodePath, 0);
if (!node && nodePath.length > 1) {
// If we're lucky the last element in the path will identify the node.
node = xml.documentElement.searchNode([nodePath.at(-1)], 0);
}
if (node) {
if (Array.isArray(value)) {
node.childNodes = value.map(val => new SimpleDOMNode("value", val));

View file

@ -782,6 +782,15 @@ class PDFDocumentProxy {
constructor(pdfInfo, transport) {
this._pdfInfo = pdfInfo;
this._transport = transport;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
// For testing purposes.
Object.defineProperty(this, "getXFADatasets", {
value: () => {
return this._transport.getXFADatasets();
},
});
}
}
/**
@ -2349,6 +2358,15 @@ class WorkerTransport {
this.downloadInfoCapability = createPromiseCapability();
this.setupMessageHandler();
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
// For testing purposes.
Object.defineProperty(this, "getXFADatasets", {
value: () => {
return this.messageHandler.sendWithPromise("GetXFADatasets", null);
},
});
}
}
#cacheSimpleMethod(name, data = null) {