Skip to content

Commit ff1af5a

Browse files
Merge pull request #20916 from calixteman/fix_co
When merging pdfs, fix the CO after the fields have been cloned
2 parents 6245bb2 + b7da4b8 commit ff1af5a

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
@@ -1476,6 +1476,7 @@ class PDFEditor {
14761476
this.currentDocument = null;
14771477
}
14781478
}
1479+
this.#setAcroFormCalculationOrder(allDocumentData);
14791480
}
14801481

14811482
#setAcroFormQ(allDocumentData) {
@@ -1511,7 +1512,6 @@ class PDFEditor {
15111512
#setAcroFormDefaultBasicValues(allDocumentData) {
15121513
let sigFlags = 0;
15131514
let needAppearances = false;
1514-
const calculationOrder = [];
15151515
for (const documentData of allDocumentData) {
15161516
if (!documentData.acroForm) {
15171517
continue;
@@ -1523,7 +1523,15 @@ class PDFEditor {
15231523
if (documentData.acroForm.get("NeedAppearances") === true) {
15241524
needAppearances = true;
15251525
}
1526-
const co = documentData.acroForm.get("CO") || null;
1526+
}
1527+
this.acroFormSigFlags = sigFlags;
1528+
this.acroFormNeedAppearances = needAppearances;
1529+
}
1530+
1531+
#setAcroFormCalculationOrder(allDocumentData) {
1532+
const calculationOrder = [];
1533+
for (const documentData of allDocumentData) {
1534+
const co = documentData.acroForm?.get("CO") || null;
15271535
if (!Array.isArray(co)) {
15281536
continue;
15291537
}
@@ -1535,8 +1543,6 @@ class PDFEditor {
15351543
}
15361544
}
15371545
}
1538-
this.acroFormSigFlags = sigFlags;
1539-
this.acroFormNeedAppearances = needAppearances;
15401546
this.acroFormCalculationOrder =
15411547
calculationOrder.length > 0 ? calculationOrder : null;
15421548
}

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,3 +887,4 @@
887887
!radial_gradients.pdf
888888
!outlines_for_editor.pdf
889889
!mesh_shading_empty.pdf
890+
!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
@@ -6398,6 +6398,34 @@ small scripts as well as for`);
63986398

63996399
await loadingTask.destroy();
64006400
});
6401+
6402+
it("preserves calculation order when it points to parent fields", async function () {
6403+
let loadingTask = getDocument(
6404+
buildGetDocumentParams("acroform_calculation_order.pdf")
6405+
);
6406+
let pdfDoc = await loadingTask.promise;
6407+
6408+
expect(await pdfDoc.getCalculationOrderIds()).toEqual(["6R"]);
6409+
expect(Object.keys((await pdfDoc.getFieldObjects()) || {})).toEqual([
6410+
"group",
6411+
]);
6412+
6413+
const data = await pdfDoc.extractPages([{ document: null }]);
6414+
await loadingTask.destroy();
6415+
6416+
loadingTask = getDocument(data);
6417+
pdfDoc = await loadingTask.promise;
6418+
6419+
const calculationOrder = await pdfDoc.getCalculationOrderIds();
6420+
expect(Array.isArray(calculationOrder)).toEqual(true);
6421+
expect(calculationOrder.length).toEqual(1);
6422+
expect(calculationOrder[0]).not.toEqual("6R");
6423+
expect(Object.keys((await pdfDoc.getFieldObjects()) || {})).toEqual([
6424+
"group",
6425+
]);
6426+
6427+
await loadingTask.destroy();
6428+
});
64016429
});
64026430

64036431
describe("Outlines", function () {

0 commit comments

Comments
 (0)