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

Method _add_file_annot

src/__init__.py:9540–9565  ·  view source on GitHub ↗
(self, point, buffer_, filename, ufilename=None, desc=None, icon=None)

Source from the content-addressed store, hash-verified

9538 return annot
9539
9540 def _add_file_annot(self, point, buffer_, filename, ufilename=None, desc=None, icon=None):
9541 page = self._pdf_page()
9542 uf = ufilename if ufilename else filename
9543 d = desc if desc else filename
9544 p = JM_point_from_py(point)
9545 filebuf = JM_BufferFromBytes(buffer_)
9546 if not filebuf.m_internal:
9547 raise TypeError( MSG_BAD_BUFFER)
9548 annot = mupdf.pdf_create_annot(page, mupdf.PDF_ANNOT_FILE_ATTACHMENT)
9549 r = mupdf.pdf_annot_rect(annot)
9550 r = mupdf.fz_make_rect(p.x, p.y, p.x + r.x1 - r.x0, p.y + r.y1 - r.y0)
9551 mupdf.pdf_set_annot_rect(annot, r)
9552 flags = mupdf.PDF_ANNOT_IS_PRINT
9553 mupdf.pdf_set_annot_flags(annot, flags)
9554
9555 if icon:
9556 mupdf.pdf_set_annot_icon_name(annot, icon)
9557
9558 val = JM_embed_file(page.doc(), filebuf, filename, uf, d, 1)
9559 mupdf.pdf_dict_put(mupdf.pdf_annot_obj(annot), PDF_NAME('FS'), val)
9560 mupdf.pdf_dict_put_text_string(mupdf.pdf_annot_obj(annot), PDF_NAME('Contents'), filename)
9561 mupdf.pdf_update_annot(annot)
9562 mupdf.pdf_set_annot_rect(annot, r)
9563 mupdf.pdf_set_annot_flags(annot, flags)
9564 JM_add_annot_id(annot, "A")
9565 return Annot(annot)
9566
9567 def _add_freetext_annot(
9568 self, rect,

Callers 1

add_file_annotMethod · 0.95

Calls 7

_pdf_pageMethod · 0.95
JM_point_from_pyFunction · 0.85
JM_BufferFromBytesFunction · 0.85
JM_embed_fileFunction · 0.85
PDF_NAMEFunction · 0.85
JM_add_annot_idFunction · 0.85
AnnotClass · 0.85

Tested by

no test coverage detected