![]() ![]() TextColor=blue, forceBorder=True, options=options)Ĭ.drawString(10, 600, 'Choose an animal:')įorm.choice(name='choice2', tooltip='Field choice2', Options = įorm.choice(name='choice1', tooltip='Field choice1', Let's take a moment to create a couple of choice widgets in a PDF document: # simple_choices.pyįrom import magenta, pink, blue, green, redĬ.drawString(10, 650, 'Choose a letter:') If you add edit to the fieldFlags, then the user can edit item in the choice widget. This allows the user to pick one or more options from the drop-down list, depending on the fieldFlags you have set. The choice widget is basically a combobox that displays a dropdown when the user clicks on it. Now let's discover how to create a choice widget! ![]() ![]() This also allows you to change the appearance of the radio when it is selected or deselected. The documentation does not state why, but I assume this is done to help ReportLab track the "selected" state of the widget. This is because you are required to create two instances of each radio button with the same name, but with different values and sections. When you run this code, you will notice that you only get 3 radios. Now let's take a moment and create a simple demo of the radio widgets: # simple_radios.pyĬ.drawCentredString(300, 700, 'Radio demo')įorm.radio(name='radio1', tooltip='Field radio1',įorm.radio(name='radio2', tooltip='Field radio2',įorm.radio(name='radio3', tooltip='Field radio3', In other words, if you create a series of radios one after the other, they will be grouped together. ReportLab does not appear to have a way to explicitly group a set of radio boxes as being together. Checkboxes are rarely limited to just allowing one checkbox per group. Radio widgets are kind of like checkboxes except that usually you put radio buttons into a group where only one radio button can be selected. If you open up the document and check all of the checkboxes, you will end up with them looking like this: I set the buttonStyle to something different for each of the checkboxes. If you turn it off though, the checkbox may become invisible, so you might want to set its background color via fillColor if you do that. You can play around with the width of the checkbox's border or turn the border off. Then we set its position and a few other things. Now let's write up a simple example that demonstrates how some of these arguments behave: # simple_checkboxes.pyįrom import magenta, pink, blue, greenĬ = canvas.Canvas('simple_checkboxes.pdf')įorm.checkbox(name='cb1', tooltip='Field cb1',įorm.checkbox(name='cb2', tooltip='Field cb2',įorm.checkbox(name='cb3', tooltip='Field cb3',įorm.checkbox(name='cb4', tooltip='Field cb4',įorm.checkbox(name='cb5', tooltip='Field cb5',Īs you can see, we set up the name and set the tooltip to basically match the name of the widget. ReportLab supports several different "check" styles though, so when the checkbox is checked, it can look different depending on the style that you set. The checkbox widget is exactly what it sounds like. Let's take a look at the widgets that ReportLab supports! Note that you can only have one form per document. In this section, we will look at the following widgets:Īll of these widgets are created by calling various methods on the canvas.acroform property. ReportLab doesn't support all of these elements, but it does cover most of them. The PDF standard actually has a fairly rich set of interactive elements. The ReportLab toolkit allows you to create interactive fillable forms. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |