21 lines
553 B
Python
21 lines
553 B
Python
import fitz # PyMuPDF
|
|
from pathlib import Path
|
|
|
|
def add_logo(input_path, output_path, logo_path, position=(80, 60), scale=0.55):
|
|
doc = fitz.open(input_path)
|
|
logo_image = str(Path(logo_path).resolve())
|
|
|
|
for page in doc:
|
|
# Load logo image dimensions
|
|
pix = fitz.Pixmap(logo_image)
|
|
width = pix.width * scale
|
|
height = pix.height * scale
|
|
|
|
x, y = position
|
|
rect = fitz.Rect(x, y, x + width, y + height)
|
|
|
|
page.insert_image(rect, filename=logo_image)
|
|
|
|
doc.save(output_path)
|
|
doc.close()
|