from ironpdf import * # Step 1. Creating a PDF with editable forms from HTML using form and input tags # Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox' form_html = """ <html> <body> <h2>Editable PDF Form</h2> <form> First name: <br> <input type='text' name='firstname' value=''> <br> Last name: <br> <input type='text' name='lastname' value=''> <br> <br> <p>Please specify your gender:</p> <input type='radio' id='female' name='gender' value= 'Female'> <label for='female'>Female</label> <br> <br> <input type='radio' id='male' name='gender' value='Male'> <label for='male'>Male</label> <br> <br> <input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'> <label for='non-binary/other'>Non-Binary / Other</label> <br> <p>Please select all medical conditions that apply:</p> <input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'> <label for='condition1'> Hypertension</label><br> <input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'> <label for='condition2'> Heart Disease</label><br> <input type='checkbox' id='condition3' name='Stoke' value='Stoke'> <label for='condition3'> Stoke</label><br> <input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'> <label for='condition4'> Diabetes</label><br> <input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'> <label for='condition5'> Kidney Disease</label><br> </form> </body> </html>""" # Instantiate Renderer renderer = ChromePdfRenderer() renderer.RenderingOptions.CreatePdfFormsFromHtml = True renderer.RenderHtmlAsPdf(form_html).SaveAs("BasicForm.pdf") # Step 2. Reading and Writing PDF form values. form_document = PdfDocument.FromFile("BasicForm.pdf") # Set and Read the value of the "firstname" field first_name_field = form_document.Form.GetFieldByName("firstname") first_name_field.Value = "Minnie" print("FirstNameField value: {}".format(first_name_field.Value)) # Set and Read the value of the "lastname" field last_name_field = form_document.Form.GetFieldByName("lastname") last_name_field.Value = "Mouse" print("LastNameField value: {}".format(last_name_field.Value)) form_document.SaveAs("FilledForm.pdf")