Когда я попытался установить пакет fitz в PyCharm, он выдал ошибку. Но когда я перешел к следующему коду
import fitz
from PIL import Image
input_file = "sample_report.pdf"
output_file = "signed sample_report.pdf"
#signature_file = "stamp.jpg"
#In case there is no image inversion problem. Also skip the line 8 to line 13 and no need for PIL import.
"""
image_file = Image.open("stamp.jpg")
image_file_rotate = image_file.transpose(Image.FLIP_LEFT_RIGHT)
image_file_rotate.save("stamp_rotated.jpg")
#Image of stamp is first rotated on it's vertical axis
image_file = Image.open("stamp_rotated.jpg")
image_file_inverted = image_file.rotate(180,expand=True)
image_file_inverted.save("stamp_inverted.jpg")
#Image of stamp is inverted to suit the visual perception
"""
signature_file = "stamp_inverted.jpg"
#Line no. 8 to 18 are attempted while countering the image inversion problem
image_rectangle = fitz.Rect(-80,-120,-540,-140)
#This step is crafting the image-box to be stamped on the input PDF file.
fitz.Rect(x1,y1,x2,y2)
#The parameters being passed in the Rect() function are the top-left corner coordinate(x1,y1) and the bottom-right corner coordinate(x2,y2)
file_handle = fitz.open(input_file)
target_page = file_handle[0]
#The target page is retrieved. The '0' signifies no change in layout.
target_page.insertImage(image_rectangle, filename=signature_file)
#Inserting the image on the target page.
file_handle.save(output_file)
#Output is generated
Теперь, хотя по большей части этот код имеет дело с проблемой инверсии изображения, я все еще борюсь с частью позиционирования. Координаты, передаваемые в коде
image_rectangle = fitz.Rect(-80,-120,-540,-140)
, не ясны в том смысле, что точка отсчета не указана. Дело не в том, что верхний левый угол является координатой (0,0). Это может быть где угодно. И я не могу понять, как его обнаружить и соответствующим образом разместить свое изображение.