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

Function write_text

src_classic/utils.py:47–114  ·  view source on GitHub ↗

Write the text of one or more TextWriter objects. Args: rect: target rectangle. If None, the union of the text writers is used. writers: one or more TextWriter objects. overlay: put in foreground or background. keep_proportion: maintain aspect ratio of rectangle

(page: Page, **kwargs)

Source from the content-addressed store, hash-verified

45
46
47def write_text(page: Page, **kwargs) -> None:
48 """Write the text of one or more TextWriter objects.
49
50 Args:
51 rect: target rectangle. If None, the union of the text writers is used.
52 writers: one or more TextWriter objects.
53 overlay: put in foreground or background.
54 keep_proportion: maintain aspect ratio of rectangle sides.
55 rotate: arbitrary rotation angle.
56 oc: the xref of an optional content object
57 """
58 if type(page) is not Page:
59 raise ValueError("bad page parameter")
60 s = {
61 k
62 for k in kwargs.keys()
63 if k
64 not in {
65 "rect",
66 "writers",
67 "opacity",
68 "color",
69 "overlay",
70 "keep_proportion",
71 "rotate",
72 "oc",
73 }
74 }
75 if s != set():
76 raise ValueError("bad keywords: " + str(s))
77
78 rect = kwargs.get("rect")
79 writers = kwargs.get("writers")
80 opacity = kwargs.get("opacity")
81 color = kwargs.get("color")
82 overlay = bool(kwargs.get("overlay", True))
83 keep_proportion = bool(kwargs.get("keep_proportion", True))
84 rotate = int(kwargs.get("rotate", 0))
85 oc = int(kwargs.get("oc", 0))
86
87 if not writers:
88 raise ValueError("need at least one TextWriter")
89 if type(writers) is TextWriter:
90 if rotate == 0 and rect is None:
91 writers.write_text(page, opacity=opacity, color=color, overlay=overlay)
92 return None
93 else:
94 writers = (writers,)
95 clip = writers[0].text_rect
96 textdoc = Document()
97 tpage = textdoc.new_page(width=page.rect.width, height=page.rect.height)
98 for writer in writers:
99 clip |= writer.text_rect
100 writer.write_text(tpage, opacity=opacity, color=color)
101 if rect is None:
102 rect = clip
103 page.show_pdf_page(
104 rect,

Callers

nothing calls this directly

Calls 5

new_pageMethod · 0.95
DocumentClass · 0.85
show_pdf_pageMethod · 0.80
getMethod · 0.45
write_textMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…