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 |
import fitz # PyMuPDF def create_simple_form(output_pdf_path, profile_picture_path): # Create a new PDF document pdf_document = fitz.open() page = pdf_document.new_page(width=595, height=842) # A4 size in points (1 inch = 72 points) # Title title = "Simple Registration Form" title_fontsize = 16 title_width = len(title) * (title_fontsize * 0.6) # Rough estimation of text width title_x_position = (595 - title_width) / 2 # Center the title horizontally # Insert the title page.insert_text((title_x_position, 50), title, fontsize=title_fontsize, fontname="helv") # Form fields with labels and sample data form_labels = [ ("First Name:", (100, 100), "Gautam"), ("Last Name:", (100, 140), "Sharma"), ("Email:", (100, 180), "gautam@example.com"), ("Age:", (100, 220), "27"), ] for label, position, sample_data in form_labels: page.insert_text(position, label, fontsize=12, fontname="helv") # Draw empty text fields with adjusted height field_rect = fitz.Rect(position[0] + 150, position[1] - 5, position[0] + 350, position[1] + 15) page.draw_rect(field_rect, color=(0, 0, 0)) # Fill in the sample data, lowering its position within the field for better centering page.insert_text((position[0] + 155, position[1] + 10), sample_data, fontsize=12, fontname="helv", color=(0, 0, 0)) # Save the PDF pdf_document.save(output_pdf_path) pdf_document.close() print(f"PDF saved as {output_pdf_path}") # Usage example output_pdf = "simple_registration_form.pdf" profile_picture_path = "profile.jpg" # Update with the correct path to your profile picture create_simple_form(output_pdf, profile_picture_path) |