Пока это мой код, он все делает правильно, но я могу получить Цвет текста и Размер текста.
Код: Выделить всё
import pymupdf
import os
# Open the PDF document
doc = pymupdf.open('input.pdf')
# Load the custom font file
font_file = os.path.join(os.path.dirname(__file__), 'BMWGroupTNCondensed-Regular.otf')
with open(font_file, 'rb') as f:
font_buffer = f.read()
# Iterate over each page of the document
for page in doc:
# Find all instances of "2024" on the current page
instances = page.search_for("2024")
# Create a list to store the replacement coordinates
replacement_coords = []
# Redact each instance of "2024" on the current page and replace with "2025"
for inst in instances:
page.add_redact_annot(inst)
replacement_coords.append((inst.x0, inst.y0))
# Apply the redactions to the current page
page.apply_redactions()
# Insert the custom font in the PDF document
page.insert_font(fontname="BMWGroupTNCondensed-Regular", fontbuffer=font_buffer)
# Insert the new text "2025" at the redacted locations using the custom font
for x, y in replacement_coords:
page.insert_text((x, y + 10), "2025", fontname="BMWGroupTNCondensed-Regular", fontsize=12)
# Save the modified document
doc.save('modified_document.pdf')
# Close the document
doc.close()
Подробнее здесь: https://stackoverflow.com/questions/787 ... pdf-editor