mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-13 16:54:03 +02:00
Merge pull request #20916 from calixteman/fix_co
When merging pdfs, fix the CO after the fields have been cloned
This commit is contained in:
commit
ff1af5a058
@ -1476,6 +1476,7 @@ class PDFEditor {
|
||||
this.currentDocument = null;
|
||||
}
|
||||
}
|
||||
this.#setAcroFormCalculationOrder(allDocumentData);
|
||||
}
|
||||
|
||||
#setAcroFormQ(allDocumentData) {
|
||||
@ -1511,7 +1512,6 @@ class PDFEditor {
|
||||
#setAcroFormDefaultBasicValues(allDocumentData) {
|
||||
let sigFlags = 0;
|
||||
let needAppearances = false;
|
||||
const calculationOrder = [];
|
||||
for (const documentData of allDocumentData) {
|
||||
if (!documentData.acroForm) {
|
||||
continue;
|
||||
@ -1523,7 +1523,15 @@ class PDFEditor {
|
||||
if (documentData.acroForm.get("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)) {
|
||||
continue;
|
||||
}
|
||||
@ -1535,8 +1543,6 @@ class PDFEditor {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.acroFormSigFlags = sigFlags;
|
||||
this.acroFormNeedAppearances = needAppearances;
|
||||
this.acroFormCalculationOrder =
|
||||
calculationOrder.length > 0 ? calculationOrder : null;
|
||||
}
|
||||
|
||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -887,3 +887,4 @@
|
||||
!radial_gradients.pdf
|
||||
!outlines_for_editor.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
|
||||
@ -6398,6 +6398,34 @@ small scripts as well as for`);
|
||||
|
||||
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 () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user