mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
XFA - Save filled data in the pdf when downloading the file (Bug 1716288)
- when binding (after parsing) we get a map between some template nodes and some data nodes; - so set user data in input handlers in using data node uids in the annotation storage; - to save the form, just put the value we have in the storage in the correct data nodes, serialize the xml as a string and then write the string at the end of the pdf using src/core/writer.js; - fix few bugs around data bindings: - the "Off" issue in Bug 1716980.
This commit is contained in:
parent
d7fdb72a3f
commit
429ffdcd2f
17 changed files with 71564 additions and 113 deletions
|
@ -123,12 +123,7 @@ function computeMD5(filesize, xrefInfo) {
|
|||
return bytesToString(calculateMD5(array));
|
||||
}
|
||||
|
||||
function updateXFA(datasetsRef, newRefs, xref) {
|
||||
if (datasetsRef === null || xref === null) {
|
||||
return;
|
||||
}
|
||||
const datasets = xref.fetchIfRef(datasetsRef);
|
||||
const str = datasets.getString();
|
||||
function writeXFADataForAcroform(str, newRefs) {
|
||||
const xml = new SimpleXMLParser({ hasAttributes: true }).parseFromString(str);
|
||||
|
||||
for (const { xfa } of newRefs) {
|
||||
|
@ -148,7 +143,17 @@ function updateXFA(datasetsRef, newRefs, xref) {
|
|||
}
|
||||
const buffer = [];
|
||||
xml.documentElement.dump(buffer);
|
||||
let updatedXml = buffer.join("");
|
||||
return buffer.join("");
|
||||
}
|
||||
|
||||
function updateXFA(xfaData, datasetsRef, newRefs, xref) {
|
||||
if (datasetsRef === null || xref === null) {
|
||||
return;
|
||||
}
|
||||
if (xfaData === null) {
|
||||
const datasets = xref.fetchIfRef(datasetsRef);
|
||||
xfaData = writeXFADataForAcroform(datasets.getString(), newRefs);
|
||||
}
|
||||
|
||||
const encrypt = xref.encrypt;
|
||||
if (encrypt) {
|
||||
|
@ -156,12 +161,12 @@ function updateXFA(datasetsRef, newRefs, xref) {
|
|||
datasetsRef.num,
|
||||
datasetsRef.gen
|
||||
);
|
||||
updatedXml = transform.encryptString(updatedXml);
|
||||
xfaData = transform.encryptString(xfaData);
|
||||
}
|
||||
const data =
|
||||
`${datasetsRef.num} ${datasetsRef.gen} obj\n` +
|
||||
`<< /Type /EmbeddedFile /Length ${updatedXml.length}>>\nstream\n` +
|
||||
updatedXml +
|
||||
`<< /Type /EmbeddedFile /Length ${xfaData.length}>>\nstream\n` +
|
||||
xfaData +
|
||||
"\nendstream\nendobj\n";
|
||||
|
||||
newRefs.push({ ref: datasetsRef, data });
|
||||
|
@ -173,8 +178,9 @@ function incrementalUpdate({
|
|||
newRefs,
|
||||
xref = null,
|
||||
datasetsRef = null,
|
||||
xfaData = null,
|
||||
}) {
|
||||
updateXFA(datasetsRef, newRefs, xref);
|
||||
updateXFA(xfaData, datasetsRef, newRefs, xref);
|
||||
|
||||
const newXref = new Dict(null);
|
||||
const refForXrefTable = xrefInfo.newRef;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue