MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / JM_put_script

Function JM_put_script

src/__init__.py:21174–21204  ·  view source on GitHub ↗

Create a JavaScript PDF action. Usable for all object types which support PDF actions, even if the argument name suggests annotations. Up to 2 key values can be specified, so JavaScript actions can be stored for '/A' and '/AA/?' keys.

(annot_obj, key1, key2, value)

Source from the content-addressed store, hash-verified

21172
21173
21174def JM_put_script(annot_obj, key1, key2, value):
21175 '''
21176 Create a JavaScript PDF action.
21177 Usable for all object types which support PDF actions, even if the
21178 argument name suggests annotations. Up to 2 key values can be specified, so
21179 JavaScript actions can be stored for '/A' and '/AA/?' keys.
21180 '''
21181 key1_obj = mupdf.pdf_dict_get(annot_obj, key1)
21182 pdf = mupdf.pdf_get_bound_document(annot_obj) # owning PDF
21183
21184 # if no new script given, just delete corresponding key
21185 if not value:
21186 if key2 is None or not key2.m_internal:
21187 mupdf.pdf_dict_del(annot_obj, key1)
21188 elif key1_obj.m_internal:
21189 mupdf.pdf_dict_del(key1_obj, key2)
21190 return
21191
21192 # read any existing script as a PyUnicode string
21193 if not key2.m_internal or not key1_obj.m_internal:
21194 script = JM_get_script(key1_obj)
21195 else:
21196 script = JM_get_script(mupdf.pdf_dict_get(key1_obj, key2))
21197
21198 # replace old script, if different from new one
21199 if value != script:
21200 newaction = JM_new_javascript(pdf, value)
21201 if not key2.m_internal:
21202 mupdf.pdf_dict_put(annot_obj, key1, newaction)
21203 else:
21204 mupdf.pdf_dict_putl(annot_obj, newaction, key1, key2)
21205
21206
21207def JM_py_from_irect(r):

Callers 1

JM_set_widget_propertiesFunction · 0.85

Calls 2

JM_get_scriptFunction · 0.85
JM_new_javascriptFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…