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 57 58 59 |
from reportlab.lib.pagesizes import A4 from reportlab.lib import colors from reportlab.pdfgen import canvas from reportlab.lib.units import inch def create_student_registration_form(output_pdf_path, logo_path, profile_picture_path): # Set up the document pdf = canvas.Canvas(output_pdf_path, pagesize=A4) width, height = A4 # Draw the logo at the top pdf.drawImage(logo_path, x=width / 2 - 50, y=height - 100, width=100, height=100) # Title pdf.setFont("Helvetica-Bold", 16) pdf.drawCentredString(width / 2, height - 130, "Student Registration Form") # Form fields with sample data pdf.setFont("Helvetica", 12) form_labels = [ ("First Name:", "Gautam Sharma"), ("Age:", "27"), ("Percentage:", "90%") ] y_position = height - 180 for label, data in form_labels: pdf.drawString(100, y_position, label) pdf.drawString(200, y_position, data) # Add sample data next to each field pdf.line(200, y_position - 2, 400, y_position - 2) # Underline y_position -= 30 # Gender radio field pdf.drawString(100, y_position, "Gender:") pdf.drawString(200, y_position, "Male") pdf.circle(240, y_position + 3, 5, stroke=1, fill=1) # Fill to show selected radio button for "Male" pdf.drawString(255, y_position, "Female") pdf.circle(310, y_position + 3, 5, stroke=1, fill=0) # Empty circle for "Female" y_position -= 30 pdf.drawString(100,y_position - 20,"Profile Picture:") pdf.drawImage(profile_picture_path,x=200,y=y_position - 80, width=100,height=100) pdf.setStrokeColor(colors.black) pdf.line(50,50,width-50,50) pdf.save() print(f"PDF saved as ${output_pdf_path}") output_pdf = "student_marksheet.pdf" logo_image = "logo.png" profile_picture = "profile.jpg" create_student_registration_form(output_pdf,logo_image,profile_picture) |