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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
from fpdf import FPDF class PDF(FPDF): def header(self): # Title at the top self.set_font("Helvetica", "B", 16) self.cell(0, 10, "Student Registration Form", ln=True, align="C") def create_form(self, logo_path, profile_picture_path): # Add logo self.image(logo_path, x=85, y=20, w=40, h=40) self.ln(50) # Move below the logo # Form fields with sample data self.set_font("Helvetica", "", 12) # Field data form_data = [ ("First Name:", "Gautam Sharma"), ("Age:", "27"), ("Percentage:", "90%") ] # Align and add each field for label, data in form_data: self.cell(40, 10, label, border=0, align="L") self.cell(0, 10, data, border="B", ln=True) # Gender radio field self.cell(40, 10, "Gender:", ln=False) # Male radio button self.cell(20, 10, "Male", ln=False) self.ellipse(x=62, y=self.get_y() + 3, w=4, h=4, style='FD') # Filled circle for "Male" # Female radio button self.cell(30, 10, "Female", ln=False) self.ellipse(x=88, y=self.get_y() + 3, w=4, h=4, style='D') # Empty circle for "Female" self.ln(10) # Line break after gender field # Profile Picture self.cell(40, 10, "Profile Picture:", ln=False) self.image(profile_picture_path, x=60, y=self.get_y() + 2, w=40, h=40) self.ln(50) # Add a line break after the profile picture # Create PDF pdf = PDF() pdf.add_page() logo_image = "logo.png" # Path to your logo profile_picture = "profile.jpg" # Path to the profile picture pdf.create_form(logo_image, profile_picture) output_pdf = "student_marksheet_fpdf.pdf" pdf.output(output_pdf) print(f"PDF saved as {output_pdf}") |