Skip to content

Commit 608184e

Browse files
committed
XFA - Create Form DOM in merging template and data trees
- Spec: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=171; - support for the 2 ways of merging: consumeData and matchTemplate; - create additional nodes in template DOM when occur node allows it; - support for global values in data DOM.
1 parent 45329af commit 608184e

File tree

10 files changed

+1599
-107
lines changed

10 files changed

+1599
-107
lines changed

src/core/document.js

+49
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import {
1717
assert,
18+
bytesToString,
1819
FormatError,
1920
info,
2021
InvalidPDFException,
@@ -28,6 +29,7 @@ import {
2829
shadow,
2930
stringToBytes,
3031
stringToPDFString,
32+
stringToUTF8String,
3133
unreachable,
3234
Util,
3335
warn,
@@ -732,6 +734,53 @@ class PDFDocument {
732734
});
733735
}
734736

737+
get xfaData() {
738+
const acroForm = this.catalog.acroForm;
739+
if (!acroForm) {
740+
return shadow(this, "xfaData", null);
741+
}
742+
743+
const xfa = acroForm.get("XFA");
744+
const entries = {
745+
"xdp:xdp": "",
746+
template: "",
747+
datasets: "",
748+
config: "",
749+
connectionSet: "",
750+
localeSet: "",
751+
stylesheet: "",
752+
"/xdp:xdp": "",
753+
};
754+
if (isStream(xfa) && !xfa.isEmpty) {
755+
entries["xdp:xdp"] = stringToUTF8String(bytesToString(xfa.getBytes()));
756+
return shadow(this, "xfaData", entries);
757+
}
758+
759+
if (Array.isArray(xfa) && xfa.length > 0) {
760+
for (let i = 0, ii = xfa.length; i < ii; i += 2) {
761+
let name;
762+
if (i === 0) {
763+
name = "xdp:xdp";
764+
} else if (i === ii - 2) {
765+
name = "/xdp:xdp";
766+
} else {
767+
name = xfa[i];
768+
}
769+
770+
if (!entries.hasOwnProperty(name)) {
771+
continue;
772+
}
773+
const data = this.xref.fetchIfRef(xfa[i + 1]);
774+
if (!isStream(data) || data.isEmpty) {
775+
continue;
776+
}
777+
entries[name] = stringToUTF8String(bytesToString(data.getBytes()));
778+
}
779+
return shadow(this, "xfaData", entries);
780+
}
781+
return shadow(this, "xfaData", null);
782+
}
783+
735784
get formInfo() {
736785
const formInfo = { hasFields: false, hasAcroForm: false, hasXfa: false };
737786
const acroForm = this.catalog.acroForm;

0 commit comments

Comments
 (0)