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

Unable to create a checked radiobutton #3481

Closed
dantard opened this issue May 15, 2024 · 1 comment
Closed

Unable to create a checked radiobutton #3481

dantard opened this issue May 15, 2024 · 1 comment
Labels
wontfix no intention to resolve

Comments

@dantard
Copy link

dantard commented May 15, 2024

Description of the bug

I'm unable to create a RADIOBUTTON which is already checked:

import fitz
from pymupdf import Widget, Rect
from pymupdf.mupdf import PDF_WIDGET_TYPE_RADIOBUTTON
doc = fitz.open()
page = doc.new_page()

widget = Widget()
widget.field_name = "radio"
widget.rect = Rect(100, 100, 120, 120)
widget.field_type = PDF_WIDGET_TYPE_RADIOBUTTON
widget.field_value = True 
page.add_widget(widget)

#page = doc[0]
#widgets = page.widgets()

#for w in widgets:
#    w.field_value = True
#    w.update()

doc.save("radio_button_pdf.pdf")
doc.close()

gives the error:

Traceback (most recent call last):
  File "/home/danilo/work/swikv3/radiob.py", line 14, in <module>
    page.add_widget(widget)
  File "/home/danilo/.local/lib/python3.10/site-packages/pymupdf/__init__.py", line 8477, in add_widget
    widget.update()
  File "/home/danilo/.local/lib/python3.10/site-packages/pymupdf/__init__.py", line 7151, in update
    self._validate()
  File "/home/danilo/.local/lib/python3.10/site-packages/pymupdf/__init__.py", line 7065, in _validate
    self._checker()  # any field_type specific checks
  File "/home/danilo/.local/lib/python3.10/site-packages/pymupdf/__init__.py", line 6956, in _checker
    kids_type, kids_value = doc.xref_get_key(self.xref, "Parent/Kids")
  File "/home/danilo/.local/lib/python3.10/site-packages/pymupdf/__init__.py", line 5789, in xref_get_key
    raise ValueError( MSG_BAD_XREF)
ValueError: bad xref

It does not happen if field_value is set to False.

I'm however able to update the value afterwards (commented code). Not sure if it is a bug or a "feature".

How to reproduce the bug

Just by running the code

PyMuPDF version

1.24.3

Operating system

Linux

Python version

3.10

@JorjMcKie
Copy link
Collaborator

This is a non-implemented feature. Radio buttons are intended to be set on or off in conjunction with others in the same group.
PyMuPDF does not currently support RB groups - this is the reason for this error.

@JorjMcKie JorjMcKie added the wontfix no intention to resolve label May 16, 2024
@JorjMcKie JorjMcKie closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix no intention to resolve
Projects
None yet
Development

No branches or pull requests

2 participants