from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
def generate_pdf_from_template(template_path, output_path, data):
c = canvas.Canvas(output_path, pagesize=letter)
# Load the template
with open(template_path, 'rb') as template_file:
template = template_file.read()
# Modify the template with data
merged_template = template.format(**data)
# Write the modified template to the PDF document
c.drawString(100, 700, merged_template)
# Save the PDF document
c.save()
# Example usage
data = {
'name': 'John Doe',
'age': 30,
'occupation': 'Software Developer'
}
generate_pdf_from_template('template.pdf', 'output.pdf', data)