I am creating a pdf certificate using fitz
python. because it contains paragraph. in the middle of paragraph I have some name age and other. I need to make it bold, how?
My code:
import fitz
def add_paragraph_to_pdf(input_pdf_path, output_pdf_path, paragraph,bold_words):
doc = fitz.open(input_pdf_path)
rect = fitz.Rect(70,230,550,500)
page = doc[0]
textbox = page.insert_textbox(rect, "") # Create an empty textbox
words = paragraph.split()
for word in words:
if word in bold_words:
font = textbox.insert_text(word)
font.set_font("Helvetica-Bold", size=12)
else:
font = textbox.insert_text(word)
font.set_font("Helvetica", size=12)
doc.save(output_pdf_path)
doc.close()
print("Paragraph with bold words added to the PDF successfully!")