Skip to content

Commit

Permalink
Add test and fix for Page.add_widget().
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-smith-artifex-com committed Jan 31, 2024
1 parent 1ff29bb commit 9e6e9cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16764,7 +16764,7 @@ def JM_new_javascript(pdf, value):
# not convertible to char*
return

res = mupdf.fz_new_buffer_from_copied_data(data)
res = mupdf.fz_new_buffer_from_copied_data(data.encode('utf8'))
source = mupdf.pdf_add_stream(pdf, res, mupdf.PdfObj(), 0)
newaction = mupdf.pdf_add_new_dict(pdf, 4)
mupdf.pdf_dict_put(newaction, PDF_NAME('S'), mupdf.pdf_new_name('JavaScript'))
Expand Down Expand Up @@ -17577,7 +17577,7 @@ def GETATTR(name):

# script (/A) -------------------------------------------------------
value = GETATTR("script")
JM_put_script(annot_obj, PDF_NAME('A'), None, value)
JM_put_script(annot_obj, PDF_NAME('A'), mupdf.PdfObj(), value)

# script (/AA/K) -------------------------------------------------------
value = GETATTR("script_stroke")
Expand Down
13 changes: 13 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,16 @@ def test_2391():
# page = pdf[0]
# field = page.first_widget
# page.delete_widget(field)


def test_add_widget():
doc = fitz.open()
page = doc.new_page()
w = fitz.Widget()
w.field_type = fitz.PDF_WIDGET_TYPE_BUTTON
w.rect = fitz.Rect(5, 5, 20, 20)
w.field_flags = fitz.PDF_BTN_FIELD_IS_PUSHBUTTON
w.field_name = "button"
w.fill_color = (0, 0, 1)
w.script = "app.alert('Hello, PDF!');"
page.add_widget(w)

0 comments on commit 9e6e9cc

Please sign in to comment.