pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
5.17k stars 495 forks source link

inconsistent radio button group behavior in Adobe Reader vs Brave browser PDF viewer #3833

Closed boulderalf closed 4 weeks ago

boulderalf commented 1 month ago

Description of the bug

radio button group behavior works as expected in Brave browser PDF viewer. ie., selecting one button unselects any other selected button. radio button group behavior does not work in Adobe Reader. ie., only one button in the group is ever selectable

How to reproduce the bug

You can run this code in a Google Collaboratory notebook (https://colab.research.google.com/drive/1iO56sRBo5yxhC_1pN4EyQmBKVKZu4Soq?usp=sharing)

Or you can run this snippet...

radio_width = radio_height = 12

doc = fitz.open()
page = doc.new_page()

for button_id in range(0,3):
  pos_x = 50 + button_id * 20
  pos_y = 50
  widget_rect = fitz.Rect(pos_x, pos_y,
                          pos_x + radio_width, pos_y + radio_height)

  # Create a new widget
  w = fitz.Widget()

  w.rect = widget_rect
  w.field_name = "some_group_name"
  w.text_color = (0, 0, 0)
  w.field_type = fitz.PDF_WIDGET_TYPE_RADIOBUTTON
  w.field_value = False 

  page.add_widget(w)
  page.draw_oval(w.rect,width=1)

pdf_file = "debug_radiobutton_group.pdf"
doc.save(pdf_file)
doc.close()

Compare radio button selectability in browser PDF viewer vs Adobe Acrobat.

image

PyMuPDF version

1.24.9

Operating system

Windows

Python version

3.10

JorjMcKie commented 4 weeks ago

While radio buttons can be created with PyMuPDF, radio button groups cannot. See the documentation here. We therefore cannot deal with potentially inconsistent behaviors in PDF viewers.