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:
Tim van der Meij 2026-03-19 21:22:43 +01:00 committed by GitHub
commit ff1af5a058
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 87 additions and 4 deletions

View File

@ -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;
}

View File

@ -887,3 +887,4 @@
!radial_gradients.pdf
!outlines_for_editor.pdf
!mesh_shading_empty.pdf
!acroform_calculation_order.pdf

View 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

View File

@ -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 () {