Add lightweight stamp tools
This commit is contained in:
@@ -227,6 +227,33 @@ class PdfDocument:
|
||||
annot.update()
|
||||
self.mark_changed()
|
||||
|
||||
def add_text_stamp(
|
||||
self,
|
||||
page_index: int,
|
||||
text: str,
|
||||
point: tuple[float, float] | None = None,
|
||||
) -> None:
|
||||
self.snapshot()
|
||||
page = self._page(page_index)
|
||||
x0, y0 = point or (96, 120)
|
||||
width = max(120, min(page.rect.width - x0 - 24, len(text) * 34 + 36))
|
||||
height = 58
|
||||
rect = fitz.Rect(x0, y0, x0 + width, y0 + height)
|
||||
annot = page.add_freetext_annot(
|
||||
rect,
|
||||
text,
|
||||
fontsize=28,
|
||||
fontname="china-s",
|
||||
text_color=(0.85, 0.05, 0.05),
|
||||
fill_color=(1, 1, 1),
|
||||
border_width=2,
|
||||
opacity=0.86,
|
||||
align=1,
|
||||
)
|
||||
annot.set_info(content=text)
|
||||
annot.update()
|
||||
self.mark_changed()
|
||||
|
||||
def insert_image(
|
||||
self,
|
||||
page_index: int,
|
||||
|
||||
Reference in New Issue
Block a user