Add configurable cover annotations

This commit is contained in:
2026-06-30 16:30:46 +08:00
parent 8e81995982
commit 5df3d6ceda
3 changed files with 89 additions and 9 deletions
+22 -2
View File
@@ -392,14 +392,34 @@ class PdfDocument:
annot.update()
self.mark_changed()
def add_cover_area(self, page_index: int) -> None:
def add_cover_area(
self,
page_index: int,
fill_color: tuple[float, float, float] = (1, 1, 1),
opacity: float = 1.0,
text: str = "",
) -> None:
self.snapshot()
page = self._page(page_index)
rect = self._default_rect(page)
annot = page.add_rect_annot(rect)
annot.set_colors(stroke=(1, 1, 1), fill=(1, 1, 1))
annot.set_colors(stroke=fill_color, fill=fill_color)
annot.set_border(width=0)
annot.set_opacity(max(0.1, min(1.0, float(opacity))))
annot.update()
if text.strip():
text_annot = page.add_freetext_annot(
rect,
text.strip(),
fontsize=16,
fontname="china-s",
text_color=(0, 0, 0),
fill_color=None,
border_width=0,
align=1,
)
text_annot.set_info(content=text.strip())
text_annot.update()
self.mark_changed()
def insert_blank_page(self, after_page_index: int | None = None) -> int: