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 diff --git a/lib/mixins/acroform.js b/lib/mixins/acroform.js index f2ce118b..9249aa4e 100644 --- a/lib/mixins/acroform.js +++ b/lib/mixins/acroform.js @@ -299,7 +299,9 @@ export default { let result = 0; Object.keys(options).forEach(key => { if (FIELD_FLAGS[key]) { - result |= FIELD_FLAGS[key]; + if (options[key]) { + result |= FIELD_FLAGS[key]; + } delete options[key]; } }); 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',