#1549·pdf-lib

Flatten is removing RadioGroups and Checkboxes

Author: wasims1Created Nov 19, 2023Updated May 24, 2026
Labelsbugneeds-triage

What were you trying to do?

First thank you so much for the great library! We're using it to process pdf. We draw text, set radio groups and checkboxes. Everything is working great. The only issue is when using form.flatten() , then checkboxes and radio groups do NOT show up in the flattened pdf.

Here's a summary psuedo-code:

const
   const form = pdfDoc.getForm();
   const pages = pdfDoc.getPages();
   const fields = form.getFields();
   const font = await pdfDoc.embedFont(StandardFonts.TimesRoman);
...
   drawText....

   radioGroup.select(value);
...
   form.flatten()
   await pdfDoc.save();

I tried everything:

  • form.flatten({ updateFieldAppearances: true }); (which i believe is the default behaviour anyways)
  • form.updatefieldappearances()
  • i even tried saving the file, loading it again and then flattening it to no avail

Any ideas on why checkboxes and radiogroups are disappearing when form.flatten() is called?

How did you attempt to do it?

see above

What actually happened?

see above

What did you expect to happen?

see above

How can we reproduce the issue?

Flattening a pdf

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response