Skip to content

Commit b7da4b8

Browse files
committed
When merging pdfs, fix the CO after the fields have been cloned
1 parent bda7456 commit b7da4b8

4 files changed

Lines changed: 39 additions & 4 deletions

File tree

src/core/editor/pdf_editor.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,7 @@ class PDFEditor {
14601460
this.currentDocument = null;
14611461
}
14621462
}
1463+
this.#setAcroFormCalculationOrder(allDocumentData);
14631464
}
14641465

14651466
#setAcroFormQ(allDocumentData) {
@@ -1495,7 +1496,6 @@ class PDFEditor {
14951496
#setAcroFormDefaultBasicValues(allDocumentData) {
14961497
let sigFlags = 0;
14971498
let needAppearances = false;
1498-
const calculationOrder = [];
14991499
for (const documentData of allDocumentData) {
15001500
if (!documentData.acroForm) {
15011501
continue;
@@ -1507,7 +1507,15 @@ class PDFEditor {
15071507
if (documentData.acroForm.get("NeedAppearances") === true) {
15081508
needAppearances = true;
15091509
}
1510-
const co = documentData.acroForm.get("CO") || null;
1510+
}
1511+
this.acroFormSigFlags = sigFlags;
1512+
this.acroFormNeedAppearances = needAppearances;
1513+
}
1514+
1515+
#setAcroFormCalculationOrder(allDocumentData) {
1516+
const calculationOrder = [];
1517+
for (const documentData of allDocumentData) {
1518+
const co = documentData.acroForm?.get("CO") || null;
15111519
if (!Array.isArray(co)) {
15121520
continue;
15131521
}
@@ -1519,8 +1527,6 @@ class PDFEditor {
15191527
}
15201528
}
15211529
}
1522-
this.acroFormSigFlags = sigFlags;
1523-
this.acroFormNeedAppearances = needAppearances;
15241530
this.acroFormCalculationOrder =
15251531
calculationOrder.length > 0 ? calculationOrder : null;
15261532
}

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,3 +886,4 @@
886886
!radial_gradients.pdf
887887
!outlines_for_editor.pdf
888888
!mesh_shading_empty.pdf
889+
!acroform_calculation_order.pdf
1.02 KB
Binary file not shown.

test/unit/api_spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6329,6 +6329,34 @@ small scripts as well as for`);
63296329

63306330
await loadingTask.destroy();
63316331
});
6332+
6333+
it("preserves calculation order when it points to parent fields", async function () {
6334+
let loadingTask = getDocument(
6335+
buildGetDocumentParams("acroform_calculation_order.pdf")
6336+
);
6337+
let pdfDoc = await loadingTask.promise;
6338+
6339+
expect(await pdfDoc.getCalculationOrderIds()).toEqual(["6R"]);
6340+
expect(Object.keys((await pdfDoc.getFieldObjects()) || {})).toEqual([
6341+
"group",
6342+
]);
6343+
6344+
const data = await pdfDoc.extractPages([{ document: null }]);
6345+
await loadingTask.destroy();
6346+
6347+
loadingTask = getDocument(data);
6348+
pdfDoc = await loadingTask.promise;
6349+
6350+
const calculationOrder = await pdfDoc.getCalculationOrderIds();
6351+
expect(Array.isArray(calculationOrder)).toEqual(true);
6352+
expect(calculationOrder.length).toEqual(1);
6353+
expect(calculationOrder[0]).not.toEqual("6R");
6354+
expect(Object.keys((await pdfDoc.getFieldObjects()) || {})).toEqual([
6355+
"group",
6356+
]);
6357+
6358+
await loadingTask.destroy();
6359+
});
63326360
});
63336361

63346362
describe("Outlines", function () {

0 commit comments

Comments
 (0)