Skip to content

Stamp annotation Rectangle on chnge stamp annotation name #473

@PCarle

Description

@PCarle

as described in doc Annotation.setName change text for stamp annotation!

but the annotation rect is not recompute for this new text, example :

### StampAnnot
# -*- coding: utf-8 -*-
import sys
print("Python", sys.version, "on", sys.platform, "\n")
import fitz
print(fitz.__doc__, "\n")

import os
print (os.getcwd())
from matplotlib.pyplot import imshow
import numpy as np
from PIL import Image

def print_descr(rect, annot):
    """Print a short description to the right of an annot rect."""
    annot.parent.insertText(rect.br + (10, 0),
                    "'%s' annotation" % annot.type[1], color = red)

doc = fitz.open()
page = doc.newPage()

annot = page.addStampAnnot(fitz.Rect(10,10,200,60))
annot.setColors(stroke=fitz.utils.getColor('red4'))
annot.setOpacity(0.5)
annot.setName("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
annot.update()

print_descr(annot.rect, annot)

page = doc.reload_page(page)
pix=page.getPixmap(matrix=fitz.Matrix(fitz.Identity).preScale(3,3),alpha=True,colorspace="RGB")

from PIL import Image, ImageTk
mode = "RGBA"
img = Image.frombytes(mode, [pix.width, pix.height], pix.samples)

from matplotlib import pyplot as plt
import matplotlib as mpl
mpl.rc("savefig", dpi=300)
plt.figure(figsize = (20,20))
fig, ax = plt.subplots(figsize=(18, 20))
ax.imshow(np.asarray(img))
#ax.imshow(plt.imread(imgdata))
plt.show()

produce :
stampBugPymupdf

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions