3

I am trying to flatten my PDF's using the PDAcroForm flatten method. The pdf I create is based on the example code for PDFBox Checkbox creation (I end up with a single page with one checkbox). However, when I call the flatten method on the PDF's Acroform, the checkbox I created disappears. Any idea what might be causing this?

Using PDFBox version: 2.0.5

jhr
  • 61
  • 5
  • 2
    Please try first updating to the current PDFBox version. – mkl Feb 27 '20 at 08:10
  • The current version is 2.0.19. The version 2.0.5 is from June 2017. There have been several bugfixes specifically related to disappearing fields when flattening. – Tilman Hausherr Feb 27 '20 at 09:40
  • 1
    Update: This bug was occurring when I would create unchecked checkboxes. After reading another [StackOverflow answer by Matyas](https://stackoverflow.com/questions/33383389/pdfbox-how-can-a-pdacroform-be-flattened/51273171#51273171), I needed to explicitly set the value of the checkbox as **unchecked**. When I was viewing the actual PDF structure, the new checkboxes that I added onto a PDF didn't have a `/V` value, but when I set the value to **unchecked** (which adds the `/V` value to `/Off`), then the flattening method didn't erase the checkboxes. – jhr Mar 02 '20 at 05:18
  • 1
    So you answered that question yourself => you can make that an answer. I'll change the example to add a comment. Sorry for the inconvenience. – Tilman Hausherr Mar 07 '20 at 12:54

1 Answers1

1

Answer:

This bug was occurring when I would create unchecked checkboxes.

After reading another StackOverflow answer by Matyas, the solution was that I needed to explicitly set the value of the checkbox as unchecked.

I was able to verify the solution by viewing the actual PDF Structure. When I wasn't explicitly setting the checkbox value, the new checkboxes that I added onto a PDF didn't have a /V value (whether the checkbox is checked or unchecked). When I explicitly set the value to unchecked (which adds the /V value to /Off), then the flattening method didn't erase the checkboxes.

Please see an updated example in PDFBOX Checkbox Creation to get the proper implementation.

jhr
  • 61
  • 5