|
37 | 37 | # Field 1: Simple Text
|
38 | 38 | #------------------------------------------------------------------------------
|
39 | 39 | r11 = fitz.Rect(50, 100, 200, 100 + lineheight) # rect of field label
|
40 |
| -r12 = r11 + (r11.width+2, 0, r11.width+2, 0) # rect of field value |
| 40 | +r12 = r11 + (r11.width+2, 0, 2 * r11.width+2, 0) # rect of field value |
41 | 41 | page.insertTextbox(r11, "simple Text field:", align = fitz.TEXT_ALIGN_RIGHT)
|
42 | 42 |
|
43 | 43 | widget = fitz.Widget() # create a widget object
|
44 | 44 | widget.border_color = blue # border color
|
45 | 45 | widget.border_width = 0.3 # border width
|
| 46 | +widget.border_style = "d" |
| 47 | +widget.border_dashes = [2, 3] |
46 | 48 | widget.field_name = "textfield-1" # field name
|
47 | 49 | widget.field_type = fitz.ANNOT_WG_TEXT # field type
|
48 | 50 | widget.fill_color = gold # field background
|
|
51 | 53 | widget.text_font = "tibo" # use font Times-Bold
|
52 | 54 | widget.text_fontsize = fontsize # set fontsize
|
53 | 55 | widget.text_maxlen = 40 # restrict to 40 characters
|
| 56 | +widget.field_value = "Times-Roman-Bold, 40 char." |
54 | 57 | annot = page.addWidget(widget) # create the field
|
55 | 58 |
|
56 | 59 | #------------------------------------------------------------------------------
|
|
68 | 71 | widget.rect = r22
|
69 | 72 | widget.text_color = blue
|
70 | 73 | widget.text_font = "ZaDb"
|
| 74 | +widget.field_value = True |
71 | 75 | annot = page.addWidget(widget)
|
72 | 76 |
|
73 | 77 | #------------------------------------------------------------------------------
|
|
81 | 85 | widget.field_name = "ListBox-1"
|
82 | 86 | widget.field_type = fitz.ANNOT_WG_LISTBOX
|
83 | 87 | widget.fill_color = gold
|
84 |
| -widget.list_values = ["Frankfurt", "Hamburg", "Stuttgart", "Hannover", "Berlin", "München", "Köln", "Potsdam"] |
85 |
| -widget.list_values.sort() # sort the choices |
| 88 | +widget.choice_values = ["Frankfurt", "Hamburg", "Stuttgart", "Hannover", "Berlin", "München", "Köln", "Potsdam"] |
| 89 | +widget.choice_values.sort() # sort the choices |
86 | 90 | widget.rect = r32
|
87 | 91 | widget.text_color = blue
|
88 |
| -widget.field_flags = 0 |
| 92 | +widget.text_fontsize = fontsize |
| 93 | +widget.field_flags = fitz.WIDGET_Ff_CommitOnSelCHange |
| 94 | +widget.field_value = widget.choice_values[-1] |
89 | 95 | annot = page.addWidget(widget)
|
90 | 96 |
|
91 | 97 | #------------------------------------------------------------------------------
|
|
99 | 105 | widget.field_name = "ComboBox-1"
|
100 | 106 | widget.field_type = fitz.ANNOT_WG_COMBOBOX
|
101 | 107 | widget.fill_color = gold
|
102 |
| -widget.list_values = ["Spanien", "Frankreich", "Holland", "Dänemark", "Schweden", "Norwegen", "England", "Polen", "Russland", "Italien", "Portugal", "Griechenland"] |
103 |
| -widget.list_values.sort() # sort the choices |
| 108 | +widget.choice_values = ["Spanien", "Frankreich", "Holland", "Dänemark", "Schweden", "Norwegen", "England", "Polen", "Russland", "Italien", "Portugal", "Griechenland"] |
| 109 | +widget.choice_values.sort() # sort the choices |
104 | 110 | widget.rect = r42
|
105 | 111 | widget.text_color = blue
|
106 | 112 | widget.text_fontsize = fontsize
|
| 113 | +widget.field_flags = fitz.WIDGET_Ff_CommitOnSelCHange |
| 114 | +widget.field_value = widget.choice_values[-1] |
107 | 115 | annot = page.addWidget(widget)
|
108 | 116 |
|
109 | 117 | #------------------------------------------------------------------------------
|
|
121 | 129 | widget.text_color = blue
|
122 | 130 | widget.text_font = "TiRo"
|
123 | 131 | widget.text_fontsize = fontsize
|
| 132 | +widget.field_value = "this\nis\na\nmulti-\nline\ntext." |
124 | 133 | annot = page.addWidget(widget)
|
125 | 134 |
|
126 |
| -doc.save("widgettest.pdf", pretty = True) |
| 135 | +doc.save("widgettest.pdf", clean = True, garbage = 4) |
0 commit comments