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

Method _add_freetext_annot

src/__init__.py:9567–9645  ·  view source on GitHub ↗
(
            self, rect,
            text,
            fontsize=11,
            fontname=None,
            text_color=None,
            fill_color=None,
            border_color=None,
            border_width=0,
            dashes=None,
            callout=None,
            line_end=mupdf.PDF_ANNOT_LE_OPEN_ARROW,
            opacity=1,
            align=0,
            rotate=0,
            richtext=False,
            style=None,
            )

Source from the content-addressed store, hash-verified

9565 return Annot(annot)
9566
9567 def _add_freetext_annot(
9568 self, rect,
9569 text,
9570 fontsize=11,
9571 fontname=None,
9572 text_color=None,
9573 fill_color=None,
9574 border_color=None,
9575 border_width=0,
9576 dashes=None,
9577 callout=None,
9578 line_end=mupdf.PDF_ANNOT_LE_OPEN_ARROW,
9579 opacity=1,
9580 align=0,
9581 rotate=0,
9582 richtext=False,
9583 style=None,
9584 ):
9585 rc = f"""<?xml version="1.0"?>
9586 <body xmlns="http://www.w3.org/1999/xtml"
9587 xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"
9588 xfa:contentType="text/html" xfa:APIVersion="Acrobat:8.0.0" xfa:spec="2.4">
9589 {text}"""
9590 page = self._pdf_page()
9591 if border_color and not richtext:
9592 raise ValueError("cannot set border_color if rich_text is False")
9593 if border_color and not text_color:
9594 text_color = border_color
9595 nfcol, fcol = JM_color_FromSequence(fill_color)
9596 ntcol, tcol = JM_color_FromSequence(text_color)
9597 r = JM_rect_from_py(rect)
9598 if mupdf.fz_is_infinite_rect(r) or mupdf.fz_is_empty_rect(r):
9599 raise ValueError( MSG_BAD_RECT)
9600 annot = mupdf.pdf_create_annot(page, mupdf.PDF_ANNOT_FREE_TEXT)
9601 annot_obj = mupdf.pdf_annot_obj(annot)
9602
9603 #insert text as 'contents' or 'RC' depending on 'richtext'
9604 if not richtext:
9605 mupdf.pdf_set_annot_contents(annot, text)
9606 else:
9607 mupdf.pdf_dict_put_text_string(annot_obj,PDF_NAME("RC"), rc)
9608 if style:
9609 mupdf.pdf_dict_put_text_string(annot_obj,PDF_NAME("DS"), style)
9610
9611 mupdf.pdf_set_annot_rect(annot, r)
9612
9613 while rotate < 0:
9614 rotate += 360
9615 while rotate >= 360:
9616 rotate -= 360
9617 if rotate != 0:
9618 mupdf.pdf_dict_put_int(annot_obj, PDF_NAME('Rotate'), rotate)
9619
9620 mupdf.pdf_set_annot_quadding(annot, align)
9621
9622 if nfcol > 0:
9623 mupdf.pdf_set_annot_color(annot, fcol[:nfcol])
9624

Callers 1

add_freetext_annotMethod · 0.95

Calls 7

_pdf_pageMethod · 0.95
JM_color_FromSequenceFunction · 0.85
JM_rect_from_pyFunction · 0.85
PDF_NAMEFunction · 0.85
JM_make_annot_DAFunction · 0.85
JM_add_annot_idFunction · 0.85
AnnotClass · 0.85

Tested by

no test coverage detected