mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-02 20:37:21 +02:00
When merging pdfs, fix the CO after the fields have been cloned
This commit is contained in:
parent
bda7456724
commit
b7da4b80a9
@ -1460,6 +1460,7 @@ class PDFEditor {
|
|||||||
this.currentDocument = null;
|
this.currentDocument = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.#setAcroFormCalculationOrder(allDocumentData);
|
||||||
}
|
}
|
||||||
|
|
||||||
#setAcroFormQ(allDocumentData) {
|
#setAcroFormQ(allDocumentData) {
|
||||||
@ -1495,7 +1496,6 @@ class PDFEditor {
|
|||||||
#setAcroFormDefaultBasicValues(allDocumentData) {
|
#setAcroFormDefaultBasicValues(allDocumentData) {
|
||||||
let sigFlags = 0;
|
let sigFlags = 0;
|
||||||
let needAppearances = false;
|
let needAppearances = false;
|
||||||
const calculationOrder = [];
|
|
||||||
for (const documentData of allDocumentData) {
|
for (const documentData of allDocumentData) {
|
||||||
if (!documentData.acroForm) {
|
if (!documentData.acroForm) {
|
||||||
continue;
|
continue;
|
||||||
@ -1507,7 +1507,15 @@ class PDFEditor {
|
|||||||
if (documentData.acroForm.get("NeedAppearances") === true) {
|
if (documentData.acroForm.get("NeedAppearances") === true) {
|
||||||
needAppearances = true;
|
needAppearances = true;
|
||||||
}
|
}
|
||||||
const co = documentData.acroForm.get("CO") || null;
|
}
|
||||||
|
this.acroFormSigFlags = sigFlags;
|
||||||
|
this.acroFormNeedAppearances = needAppearances;
|
||||||
|
}
|
||||||
|
|
||||||
|
#setAcroFormCalculationOrder(allDocumentData) {
|
||||||
|
const calculationOrder = [];
|
||||||
|
for (const documentData of allDocumentData) {
|
||||||
|
const co = documentData.acroForm?.get("CO") || null;
|
||||||
if (!Array.isArray(co)) {
|
if (!Array.isArray(co)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1519,8 +1527,6 @@ class PDFEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.acroFormSigFlags = sigFlags;
|
|
||||||
this.acroFormNeedAppearances = needAppearances;
|
|
||||||
this.acroFormCalculationOrder =
|
this.acroFormCalculationOrder =
|
||||||
calculationOrder.length > 0 ? calculationOrder : null;
|
calculationOrder.length > 0 ? calculationOrder : null;
|
||||||
}
|
}
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -886,3 +886,4 @@
|
|||||||
!radial_gradients.pdf
|
!radial_gradients.pdf
|
||||||
!outlines_for_editor.pdf
|
!outlines_for_editor.pdf
|
||||||
!mesh_shading_empty.pdf
|
!mesh_shading_empty.pdf
|
||||||
|
!acroform_calculation_order.pdf
|
||||||
|
|||||||
48
test/pdfs/acroform_calculation_order.pdf
Executable file
48
test/pdfs/acroform_calculation_order.pdf
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
%PDF-1.7
|
||||||
|
1 0 obj
|
||||||
|
<< /Type /Catalog /Pages 2 0 R /AcroForm 5 0 R >>
|
||||||
|
endobj
|
||||||
|
2 0 obj
|
||||||
|
<< /Type /Pages /Kids [3 0 R] /Count 1 >>
|
||||||
|
endobj
|
||||||
|
3 0 obj
|
||||||
|
<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 200] /Resources << /Font << /F1 9 0 R >> >> /Contents 4 0 R /Annots [7 0 R 8 0 R] >>
|
||||||
|
endobj
|
||||||
|
4 0 obj
|
||||||
|
<< /Length 36 >>
|
||||||
|
stream
|
||||||
|
BT /F1 12 Tf 10 100 Td (Hello) Tj ET
|
||||||
|
endstream
|
||||||
|
endobj
|
||||||
|
5 0 obj
|
||||||
|
<< /Fields [6 0 R] /CO [6 0 R] /DA (/F1 12 Tf 0 g) >>
|
||||||
|
endobj
|
||||||
|
6 0 obj
|
||||||
|
<< /FT /Tx /T (group) /Kids [7 0 R 8 0 R] /DA (/F1 12 Tf 0 g) >>
|
||||||
|
endobj
|
||||||
|
7 0 obj
|
||||||
|
<< /Type /Annot /Subtype /Widget /Parent 6 0 R /Rect [10 150 90 170] /P 3 0 R >>
|
||||||
|
endobj
|
||||||
|
8 0 obj
|
||||||
|
<< /Type /Annot /Subtype /Widget /Parent 6 0 R /Rect [10 120 90 140] /P 3 0 R >>
|
||||||
|
endobj
|
||||||
|
9 0 obj
|
||||||
|
<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>
|
||||||
|
endobj
|
||||||
|
xref
|
||||||
|
0 10
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000009 00000 n
|
||||||
|
0000000074 00000 n
|
||||||
|
0000000131 00000 n
|
||||||
|
0000000279 00000 n
|
||||||
|
0000000365 00000 n
|
||||||
|
0000000434 00000 n
|
||||||
|
0000000514 00000 n
|
||||||
|
0000000610 00000 n
|
||||||
|
0000000706 00000 n
|
||||||
|
trailer
|
||||||
|
<< /Size 10 /Root 1 0 R >>
|
||||||
|
startxref
|
||||||
|
776
|
||||||
|
%%EOF
|
||||||
@ -6329,6 +6329,34 @@ small scripts as well as for`);
|
|||||||
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves calculation order when it points to parent fields", async function () {
|
||||||
|
let loadingTask = getDocument(
|
||||||
|
buildGetDocumentParams("acroform_calculation_order.pdf")
|
||||||
|
);
|
||||||
|
let pdfDoc = await loadingTask.promise;
|
||||||
|
|
||||||
|
expect(await pdfDoc.getCalculationOrderIds()).toEqual(["6R"]);
|
||||||
|
expect(Object.keys((await pdfDoc.getFieldObjects()) || {})).toEqual([
|
||||||
|
"group",
|
||||||
|
]);
|
||||||
|
|
||||||
|
const data = await pdfDoc.extractPages([{ document: null }]);
|
||||||
|
await loadingTask.destroy();
|
||||||
|
|
||||||
|
loadingTask = getDocument(data);
|
||||||
|
pdfDoc = await loadingTask.promise;
|
||||||
|
|
||||||
|
const calculationOrder = await pdfDoc.getCalculationOrderIds();
|
||||||
|
expect(Array.isArray(calculationOrder)).toEqual(true);
|
||||||
|
expect(calculationOrder.length).toEqual(1);
|
||||||
|
expect(calculationOrder[0]).not.toEqual("6R");
|
||||||
|
expect(Object.keys((await pdfDoc.getFieldObjects()) || {})).toEqual([
|
||||||
|
"group",
|
||||||
|
]);
|
||||||
|
|
||||||
|
await loadingTask.destroy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Outlines", function () {
|
describe("Outlines", function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user