Skip to content

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

@RicoBrase

Description

@RicoBrase

Bug Report

Description of the problem

When using acroforms, setting a boolean option to false will still add the flag to the PDF document.
This is caused by the function resolveFlags(options) in lib/mixins/acroforms.js not checking the value of the options - as long as a corresponding key is set to any value (even undefined), their flag is added to the field.

Example:
The option password is explicitly set to false, but the form text gets rendered with the password flag (only asterisks shown).

image
(Screenshot uses the code sample from below.)

I am currently creating a pull request, which will fix this issue.
PR #1496 is ready.

Code sample

I forked the repo and modified the example in the webpack folder:

var doc = new PDFDocument();
doc.registerFont('Roboto', 'fonts/Roboto-Regular.ttf');

doc.initForm();

var opts = {
    value: "sample",
    password: false
};

doc.formText("example", 100, 100, 200, 40, opts);

// waitForData must be called before call to doc.end()
waitForData(doc)
  .then(dataUrl => {
    // display the document in the iframe to the right
    iframe.src = dataUrl;
  })
  .catch(error => {
    console.log(error);
  });

doc.end();

Your environment

  • pdfkit version: 0.14.0(forked from master)
  • Node version: v20.11.0
  • Browser version (if applicable): Chrome 121.0.6167.139 (arm64)
  • Operating System: macOS Sonoma 14.3 (M1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions