app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from fpdf import FPDF pdf = FPDF() # Set margins: left, top, right pdf.set_margins(left=20, top=20, right=20) pdf.add_page() # Set font pdf.set_font("Arial", size=12) # Read the file with open("india.txt", "r", encoding="utf-8") as f: text = f.read() # Add content with uniform spacing and wrapping pdf.multi_cell(0, 10, txt=text, align='J') # 0 width = full page width (respecting margins) # Save the PDF pdf.output("formatted_output.pdf") print("PDF saved as formatted_output.pdf") |