From b5fdeda55a3afe2e68afc5b0cb42bd2900b7db1f Mon Sep 17 00:00:00 2001 From: Rico Brase Date: Sun, 4 Feb 2024 23:09:16 +0100 Subject: [PATCH 1/4] Add an option check to acroform mixin _resolveFlags(). This resolves #1495. --- lib/mixins/acroform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mixins/acroform.js b/lib/mixins/acroform.js index f2ce118b..c560c575 100644 --- a/lib/mixins/acroform.js +++ b/lib/mixins/acroform.js @@ -298,7 +298,7 @@ export default { _resolveFlags(options) { let result = 0; Object.keys(options).forEach(key => { - if (FIELD_FLAGS[key]) { + if (FIELD_FLAGS[key] && !!options[key]) { result |= FIELD_FLAGS[key]; delete options[key]; } From aca8ca8a0fed2d7a2dfa5aa63bfd62114ae2a2c0 Mon Sep 17 00:00:00 2001 From: Rico Brase Date: Mon, 5 Feb 2024 21:05:19 +0100 Subject: [PATCH 2/4] Reworked fix to remove flags from options, if they are falsey. --- lib/mixins/acroform.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/mixins/acroform.js b/lib/mixins/acroform.js index c560c575..9249aa4e 100644 --- a/lib/mixins/acroform.js +++ b/lib/mixins/acroform.js @@ -298,8 +298,10 @@ export default { _resolveFlags(options) { let result = 0; Object.keys(options).forEach(key => { - if (FIELD_FLAGS[key] && !!options[key]) { - result |= FIELD_FLAGS[key]; + if (FIELD_FLAGS[key]) { + if (options[key]) { + result |= FIELD_FLAGS[key]; + } delete options[key]; } }); From 1362c15c41ea1ba4e2df9f7add306ca06d62da55 Mon Sep 17 00:00:00 2001 From: Rico Brase Date: Mon, 5 Feb 2024 21:06:04 +0100 Subject: [PATCH 3/4] Added unit test for ignoring false flags in acroforms --- tests/unit/acroform.spec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/unit/acroform.spec.js b/tests/unit/acroform.spec.js index 4b39e28e..c75e464e 100644 --- a/tests/unit/acroform.spec.js +++ b/tests/unit/acroform.spec.js @@ -212,6 +212,33 @@ describe('acroform', () => { expect(docData).toContainChunk(expected); }); + test('false flags should be ignored', () => { + const expectedDoc = new PDFDocument({ + info: { CreationDate: new Date(Date.UTC(2018, 1, 1)) } + }); + expectedDoc.initForm(); + const expectedDocData = logData(expectedDoc); + let emptyOpts = { + align: 'center' + }; + expectedDoc.formText('flags', 20, 20, 50, 20, emptyOpts); + + doc.initForm(); + const docData = logData(doc); + let opts = { + required: false, + noExport: false, + readOnly: false, + align: 'center', + multiline: false, + password: false, + noSpell: false + }; + doc.formText('flags', 20, 20, 50, 20, opts); + + expect(docData).toContainChunk(expectedDocData); + }); + test('font size', () => { const expected = [ '11 0 obj', From 8d892b577b470238bb90da86c65b5d5aeefc9e33 Mon Sep 17 00:00:00 2001 From: Rico Brase Date: Mon, 5 Feb 2024 21:07:55 +0100 Subject: [PATCH 4/4] Added entry for removing false flags in changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2700583a..0a186e32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix for line breaks in list items (#1486) - Fix for soft hyphen not being replaced by visible hyphen if necessary (#457) - Optimize output files by ignoring identity transforms +- Fix for Acroforms - setting an option to false will still apply the flag (#1495) ### [v0.14.0] - 2023-11-09