File size: 803 Bytes
9f21f05 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from fpdf import FPDF
from datetime import datetime
import os
def create_pdf(input_text):
# Create instance of FPDF class
pdf = FPDF()
# Add a page
pdf.add_page()
# Set font
pdf.set_font("Arial", size=10)
# Split the input text into multiple lines if necessary
# This ensures that the text fits the page and multiple pages are handled
pdf.multi_cell(0, 5, txt=input_text)
# Create a unique file name with the current time
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
file_name = f"PDFs/Aditya_{timestamp}.pdf"
# Create output directory if it doesn't exist
os.makedirs(os.path.dirname(file_name), exist_ok=True)
# Save the PDF
pdf.output(file_name)
# Return the file path
return file_name |