Skip to content

Strange behavior for page.deleteAnnot on 1.16.9 compare to 1.13.20 #417

Closed
@PCarle

Description

@PCarle

with the code bellow i hope at end only one polyannot in pixmap!


from __future__ import print_function
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)
    
red    = (1, 0, 0)
blue   = (0, 0, 1)
gold   = (1, 1, 0)
colors = {"stroke": blue, "fill": gold}
colors2 = {"fill": blue, "stroke": gold}
border = {"width": 1.3}
displ = fitz.Rect(0, 50, 0, 50)
r = fitz.Rect(50, 100, 220, 135)
t1 = u"têxt üsès Lätiñ charß,\nEUR: €, mu: µ, super scripts: ²³!"

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

annot=None
for i in range (7):
    if annot is not None :
        print ("<----delete annot",i-1)
        page.deleteAnnot(annot)
    annot = page.addPolygonAnnot([r.bl, r.br, r.tr,r.tl])
    annot.setOpacity(0.5)
    annot.setBorder(border)
    annot.setColors(stroke=blue,fill=blue)
    annot.update()
    print_descr(annot.rect, annot)
    print("----> add annot",i)
    r+=displ
    


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

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))

draw pymupdf 1 16 9

with pymupdf version 1.13.20 :

  # -*- coding: utf-8 -*-
from __future__ import print_function
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)
    
red    = (1, 0, 0)
blue   = (0, 0, 1)
gold   = (1, 1, 0)
colors = {"stroke": blue, "fill": gold}
colors2 = {"fill": blue, "stroke": gold}
border = {"width": 1.3}
displ = fitz.Rect(0, 50, 0, 50)
r = fitz.Rect(50, 100, 220, 135)
t1 = u"têxt üsès Lätiñ charß,\nEUR: €, mu: µ, super scripts: ²³!"

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

annot=None
for i in range (7):
    if annot is not None :
        print ("<----delete annot",i-1)
        page.deleteAnnot(annot)
    annot = page.addPolygonAnnot([r.bl, r.br, r.tr,r.tl])
    annot.setOpacity(0.5)
    annot.setBorder(border)
    annot.setColors(colors2)
    print_descr(annot.rect, annot)
    print("----> add annot",i)
    r+=displ


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

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))

result is as expected :
draw pymupdf 1 13 20

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions