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)
| 20124 | |
| 20125 | |
| 20126 | def 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 | |
| 20157 | def JM_have_operation(pdf): |
no test coverage detected
searching dependent graphs…