Initial commit of Roster
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
import fitz # PyMuPDF
|
||||
from pathlib import Path
|
||||
from utils.text_metrics import get_text_width
|
||||
|
||||
def add_date(input_path, output_path, month_year, font_path, position=("right", 30), font_size=22):
|
||||
doc = fitz.open(input_path)
|
||||
font_path = str(Path(font_path).resolve())
|
||||
|
||||
for page in doc:
|
||||
page_width = page.rect.width
|
||||
|
||||
# Register font and get its name
|
||||
page.insert_font(fontname="custom", fontfile=font_path)
|
||||
font_name = "custom"
|
||||
|
||||
# Measure exact pixel width
|
||||
text_width = get_text_width(month_year, font_path, font_size)
|
||||
|
||||
# Calculate X position
|
||||
x = page_width - text_width - 40 if position[0] == "right" else position[0]
|
||||
y = position[1]
|
||||
|
||||
# Insert the text
|
||||
page.insert_text(
|
||||
(x, y),
|
||||
month_year,
|
||||
fontname=font_name,
|
||||
fontsize=font_size,
|
||||
color=(0, 0, 0),
|
||||
)
|
||||
|
||||
doc.save(output_path)
|
||||
doc.close()
|
||||
@@ -0,0 +1,20 @@
|
||||
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()
|
||||
@@ -0,0 +1,26 @@
|
||||
import fitz # PyMuPDF
|
||||
|
||||
LETTER_WIDTH = 792 # 8.5 inches
|
||||
LETTER_HEIGHT = 612 # 11 inches
|
||||
BOTTOM_MARGIN = 30
|
||||
|
||||
def adjust_layout(input_path, output_path, shift_amount):
|
||||
doc = fitz.open(input_path)
|
||||
new_doc = fitz.open()
|
||||
|
||||
for page in doc:
|
||||
rect = page.rect
|
||||
|
||||
# Keep original width, enforce standard height
|
||||
new_rect = fitz.Rect(0, 0, LETTER_WIDTH, LETTER_HEIGHT)
|
||||
new_page = new_doc.new_page(width=new_rect.width, height=new_rect.height)
|
||||
|
||||
# Shift original content down by shift_amount
|
||||
# Clip it back to fit on a Letter-sized page
|
||||
content_rect = fitz.Rect(0, shift_amount, rect.width, rect.height + shift_amount - BOTTOM_MARGIN)
|
||||
|
||||
new_page.show_pdf_page(content_rect, doc, page.number)
|
||||
|
||||
new_doc.save(output_path)
|
||||
new_doc.close()
|
||||
doc.close()
|
||||
Reference in New Issue
Block a user