Skip to content

Question: is PyMuPDF rect compatible with reportlab rect? #348

@ghost

Description

Dear developers,

I was trying to use coordinates obtained from PyMuPDF in reportlab but it seems they are not compatible or I am missing something. I am using rect [72, 74, 103, 85] to place free text annotation and you can see that reportlab places it at the bottom meanwhile fitz on top. My system and environment info can be found in #347
Thank you so much for your help to demystify this.

word1.pdf
word1_fitz.pdf
word1_reportlab.pdf

The code that generates word1_fitz.pdf:

import fitz

doc = fitz.open("word1.pdf")
color1 = [0.941, 0.976, 0.91]
# text color
black = (0, 0, 0)
border = {"width": 1}

# work with first page only
page = doc[0]

# get list of text locations, restricting to the first occurrence
anno = page.addFreetextAnnot(fitz.Rect(72, 74, 103, 85), "DM.USBUJ", fontsize=7, fontname="ti")

anno.setFlags(0)
anno.setBorder(border)
anno.update(fill_color=color1)
doc.save("word1_fitz.pdf")

The code that generates word1_reportlab.pdf:

from reportlab.pdfgen import canvas

c = canvas.Canvas("word1_reportlab.pdf")
c.drawString(100, 750, "")
  
body_style = '(0 0 0 rg /Arial,Bold 9 Tf)'
rect = [72, 74, 103, 85]
color = '[0.941 0.976 0.91]'
anno = "DM.USBUJ"

c.freeTextAnnotation(anno, DA=body_style, Rect=rect, C=color)  
c.save()

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions