from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter from reportlab.lib.colors import black, blue def create_form_pdf(filename): c = canvas.Canvas(filename, pagesize=letter) c.setFont("Helvetica", 20) c.drawString(50, 750, "Test Form Fields") c.setFont("Helvetica", 12) c.drawString(50, 700, "Name:") form = c.acroForm form.textfield( name='fname', tooltip='First Name', x=110, y=695, borderStyle='inset', borderColor=black, fillColor=None, width=200, height=20, textColor=blue, forceBorder=True, value='Jane Doe' ) c.drawString(50, 650, "Subscribe to newsletter:") form.checkbox( name='cb1', tooltip='Subscribe', x=200, y=645, buttonStyle='check', borderColor=black, fillColor=None, textColor=blue, forceBorder=True, checked=True ) c.drawString(50, 600, "Gender:") c.drawString(110, 600, "Male") c.drawString(170, 600, "Female") form.radio( name='radio1', tooltip='Gender', value='Male', selected=False, x=145, y=595, buttonStyle='cross', borderStyle='solid', shape='circle', borderColor=black, fillColor=None, textColor=blue, forceBorder=True ) form.radio( name='radio1', tooltip='Gender', value='Female', selected=True, x=225, y=595, buttonStyle='cross', borderStyle='solid', shape='circle', borderColor=black, fillColor=None, textColor=blue, forceBorder=True ) c.drawString(50, 550, "Country:") form.choice( name='country', tooltip='Country', value='USA', options=[('USA', 'United States'), ('CAN', 'Canada'), ('UK', 'United Kingdom')], x=110, y=545, width=150, height=20, borderStyle='solid', borderColor=black, fillColor=None, textColor=blue, forceBorder=True ) c.save() if __name__ == "__main__": create_form_pdf("test_form.pdf") print("test_form.pdf created successfully.")