from ironpdf import * # Paso 1. Crear un PDF con formularios editables a partir de HTML Creación de un PDF con formularios editables a partir de HTML utilizando etiquetas de formulario y de entrada # Radio Button y Checkbox también se pueden implementar con el tipo de entrada 'radio' y '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>""" # Instanciar renderizador renderer = ChromePdfRenderer() renderer.RenderingOptions.CreatePdfFormsFromHtml = True renderer.RenderHtmlAsPdf(form_html).SaveAs("BasicForm.pdf") # Paso 2. Lectura y escritura de valores de formularios PDF. form_document = PdfDocument.FromFile("BasicForm.pdf") # Fijar y leer el valor del campo "firstname first_name_field = form_document.Form.GetFieldByName("firstname") first_name_field.Value = "Minnie" print("FirstNameField value: {}".format(first_name_field.Value)) # Establecer y leer el valor del campo "apellido 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")