Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Acroforms - setting an option to false will still apply the flag #1496

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion lib/mixins/acroform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/acroform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down