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

Function JM_create_widget

src/__init__.py:19130–19177  ·  view source on GitHub ↗
(doc, page, type, fieldname)

Source from the content-addressed store, hash-verified

19128# Copied from MuPDF v1.14
19129# Create widget
19130def JM_create_widget(doc, page, type, fieldname):
19131 old_sigflags = mupdf.pdf_to_int(mupdf.pdf_dict_getp(mupdf.pdf_trailer(doc), "Root/AcroForm/SigFlags"))
19132 #log( '*** JM_create_widget()')
19133 #log( f'{mupdf.pdf_create_annot_raw=}')
19134 #log( f'{page=}')
19135 #log( f'{mupdf.PDF_ANNOT_WIDGET=}')
19136 annot = mupdf.pdf_create_annot_raw(page, mupdf.PDF_ANNOT_WIDGET)
19137 annot_obj = mupdf.pdf_annot_obj(annot)
19138 try:
19139 JM_set_field_type(doc, annot_obj, type)
19140 mupdf.pdf_dict_put_text_string(annot_obj, PDF_NAME('T'), fieldname)
19141
19142 if type == mupdf.PDF_WIDGET_TYPE_SIGNATURE:
19143 sigflags = old_sigflags | (SigFlag_SignaturesExist | SigFlag_AppendOnly)
19144 mupdf.pdf_dict_putl(
19145 mupdf.pdf_trailer(doc),
19146 mupdf.pdf_new_int(sigflags),
19147 PDF_NAME('Root'),
19148 PDF_NAME('AcroForm'),
19149 PDF_NAME('SigFlags'),
19150 )
19151 # pdf_create_annot will have linked the new widget into the page's
19152 # annot array. We also need it linked into the document's form
19153 form = mupdf.pdf_dict_getp(mupdf.pdf_trailer(doc), "Root/AcroForm/Fields")
19154 if not form.m_internal:
19155 form = mupdf.pdf_new_array(doc, 1)
19156 mupdf.pdf_dict_putl(
19157 mupdf.pdf_trailer(doc),
19158 form,
19159 PDF_NAME('Root'),
19160 PDF_NAME('AcroForm'),
19161 PDF_NAME('Fields'),
19162 )
19163 mupdf.pdf_array_push(form, annot_obj) # Cleanup relies on this statement being last
19164 except Exception:
19165 if g_exceptions_verbose: exception_info()
19166 mupdf.pdf_delete_annot(page, annot)
19167
19168 if type == mupdf.PDF_WIDGET_TYPE_SIGNATURE:
19169 mupdf.pdf_dict_putl(
19170 mupdf.pdf_trailer(doc),
19171 mupdf.pdf_new_int(old_sigflags),
19172 PDF_NAME('Root'),
19173 PDF_NAME('AcroForm'),
19174 PDF_NAME('SigFlags'),
19175 )
19176 raise
19177 return annot
19178
19179
19180def JM_cropbox(page_obj):

Callers 1

_addWidgetMethod · 0.85

Calls 4

JM_set_field_typeFunction · 0.85
PDF_NAMEFunction · 0.85
exception_infoFunction · 0.85
pdf_trailerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…