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

Function JM_get_script

src/__init__.py:20126–20154  ·  view source on GitHub ↗

JavaScript extractor Returns either the script source or None. Parameter is a PDF action dictionary, which must have keys /S and /JS. The value of /S must be '/JavaScript'. The value of /JS is returned.

(key)

Source from the content-addressed store, hash-verified

20124
20125
20126def JM_get_script(key):
20127 '''
20128 JavaScript extractor
20129 Returns either the script source or None. Parameter is a PDF action
20130 dictionary, which must have keys /S and /JS. The value of /S must be
20131 '/JavaScript'. The value of /JS is returned.
20132 '''
20133 if not key.m_internal:
20134 return
20135
20136 j = mupdf.pdf_dict_get(key, PDF_NAME('S'))
20137 jj = mupdf.pdf_to_name(j)
20138 if jj == "JavaScript":
20139 js = mupdf.pdf_dict_get(key, PDF_NAME('JS'))
20140 if not js.m_internal:
20141 return
20142 else:
20143 return
20144
20145 if mupdf.pdf_is_string(js):
20146 script = JM_UnicodeFromStr(mupdf.pdf_to_text_string(js))
20147 elif mupdf.pdf_is_stream(js):
20148 res = mupdf.pdf_load_stream(js)
20149 script = JM_EscapeStrFromBuffer(res)
20150 else:
20151 return
20152 if script: # do not return an empty script
20153 return script
20154 return
20155
20156
20157def JM_have_operation(pdf):

Callers 2

JM_get_widget_propertiesFunction · 0.85
JM_put_scriptFunction · 0.85

Calls 3

PDF_NAMEFunction · 0.85
JM_UnicodeFromStrFunction · 0.85
JM_EscapeStrFromBufferFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…