@@ -102,9 +102,70 @@ class _object:
102
102
103
103
104
104
VersionFitz = "1.13.0"
105
- VersionBind = "1.13.9"
106
- VersionDate = "2018-06-09 15:14:41"
107
- version = (VersionBind , VersionFitz , "20180609151441" )
105
+ VersionBind = "1.13.10"
106
+ VersionDate = "2018-06-14 07:13:02"
107
+ version = (VersionBind , VersionFitz , "20180614071302" )
108
+
109
+
110
+ #------------------------------------------------------------------------------
111
+ # Class describing a PDF form field ("widget")
112
+ #------------------------------------------------------------------------------
113
+ class Widget ():
114
+ def __init__ (self ):
115
+ self .border_color = None # annot value
116
+ self .border_style = None # annot value
117
+ self .border_width = 0 # annot value
118
+ self .list_ismultiselect = False # list- / comboboxes
119
+ self .list_values = None # list- / comboboxes
120
+ self .field_name = None # field name
121
+ self .field_value = None # supports all field types
122
+ self .fill_color = None
123
+ self .pb_caption = None # pushbutton text
124
+ self .rect = None # annot value
125
+ self .text_color = None # text fields only
126
+ self .text_maxlen = 0 # text fields only
127
+ self .text_type = 0 # text fields only
128
+ self .field_type = - 1 # valid range 0 through 6
129
+ self .field_type_text = None
130
+ if str is not bytes :
131
+ unicode = str
132
+ self ._str_types = (str , unicode ) if str is bytes else (str )
133
+
134
+ def _validate (self ):
135
+ checker = (self ._check0 , self ._check1 , self ._check2 , self ._check3 ,
136
+ self ._check4 , self ._check5 )
137
+ valid_types = tuple (range (6 ))
138
+ if self .field_type not in valid_types :
139
+ raise NotImplementedError ("unsupported widget type" )
140
+ if type (self .rect ) is not Rect :
141
+ raise ValueError ("invalid rect" )
142
+ if not self .field_name :
143
+ raise ValueError ("field name missing" )
144
+ checker [self .type ](self )
145
+
146
+ def _check0 (self ):
147
+ if any ([self .text_color , self .text_maxlen , self .text_type ,
148
+ self .list_ismultiselect , self .list_values ]):
149
+ raise ValueError ("invalid value(s) for PushButton" )
150
+ if type (self .pb_caption ) not in self ._str_types :
151
+ raise ValueError ("caption must be a string" )
152
+
153
+ def _check1 (self ):
154
+ return
155
+
156
+ def _check2 (self ):
157
+ return
158
+
159
+ def _check3 (self ):
160
+ if len (self .field_value ) > self .text_maxlen :
161
+ raise ValueError ("length of text exceeds maxlwn" )
162
+ return
163
+
164
+ def _check4 (self ):
165
+ return
166
+
167
+ def _check5 (self ):
168
+ return
108
169
109
170
110
171
#------------------------------------------------------------------------------
@@ -272,13 +333,13 @@ def getPDFstr(x):
272
333
273
334
return "(" + r + ")"
274
335
275
- #===============================================================================
336
+ #------------------------------------------------------------------------------
276
337
# Return a PDF string suitable for the TJ operator enclosed in "[]" brackets.
277
338
# The input string is converted to either 2 or 4 hex digits per character.
278
339
# If no glyphs are supplied, then a simple font is assumed and each character
279
340
# taken directly.
280
341
# Otherwise a char's glyph is taken and 4 hex digits per char are put out.
281
- #===============================================================================
342
+ #------------------------------------------------------------------------------
282
343
def getTJstr (text , glyphs ):
283
344
if text .startswith ("[<" ) and text .endswith (">]" ): # already done
284
345
return text
@@ -479,7 +540,6 @@ def ConversionTrailer(i):
479
540
480
541
return r
481
542
482
-
483
543
class Document (_object ):
484
544
"""open() - new empty PDF
485
545
open('type', stream) - from bytes/bytearray
@@ -1178,7 +1238,7 @@ def getSVGimage(self, matrix=None):
1178
1238
1179
1239
1180
1240
def addLineAnnot (self , p1 , p2 ):
1181
- """addLineAnnot(self, p1, p2) -> Annot """
1241
+ """Add a Line annotation between Points p1, p2"""
1182
1242
CheckParent (self )
1183
1243
1184
1244
val = _fitz .Page_addLineAnnot (self , p1 , p2 )
@@ -1193,7 +1253,7 @@ def addLineAnnot(self, p1, p2):
1193
1253
1194
1254
1195
1255
def addTextAnnot (self , point , text ):
1196
- """addTextAnnot(self, point, text) -> Annot """
1256
+ """Add a 'sticky note' at Point pos """
1197
1257
CheckParent (self )
1198
1258
1199
1259
val = _fitz .Page_addTextAnnot (self , point , text )
@@ -1208,7 +1268,7 @@ def addTextAnnot(self, point, text):
1208
1268
1209
1269
1210
1270
def addStrikeoutAnnot (self , rect ):
1211
- """addStrikeoutAnnot(self, rect) -> Annot """
1271
+ """Strike out content in a Rect """
1212
1272
CheckParent (self )
1213
1273
1214
1274
val = _fitz .Page_addStrikeoutAnnot (self , rect )
@@ -1223,7 +1283,7 @@ def addStrikeoutAnnot(self, rect):
1223
1283
1224
1284
1225
1285
def addUnderlineAnnot (self , rect ):
1226
- """addUnderlineAnnot(self, rect) -> Annot """
1286
+ """Underline content in a Rect """
1227
1287
CheckParent (self )
1228
1288
1229
1289
val = _fitz .Page_addUnderlineAnnot (self , rect )
@@ -1238,7 +1298,7 @@ def addUnderlineAnnot(self, rect):
1238
1298
1239
1299
1240
1300
def addHighlightAnnot (self , rect ):
1241
- """addHighlightAnnot(self, rect) -> Annot """
1301
+ """Highlight content in a Rect """
1242
1302
CheckParent (self )
1243
1303
1244
1304
val = _fitz .Page_addHighlightAnnot (self , rect )
@@ -1253,7 +1313,7 @@ def addHighlightAnnot(self, rect):
1253
1313
1254
1314
1255
1315
def addRectAnnot (self , rect ):
1256
- """addRectAnnot(self, rect) -> Annot """
1316
+ """Add a rectangle annotation """
1257
1317
CheckParent (self )
1258
1318
1259
1319
val = _fitz .Page_addRectAnnot (self , rect )
@@ -1268,7 +1328,7 @@ def addRectAnnot(self, rect):
1268
1328
1269
1329
1270
1330
def addCircleAnnot (self , rect ):
1271
- """addCircleAnnot(self, rect) -> Annot """
1331
+ """Add a circle annotation """
1272
1332
CheckParent (self )
1273
1333
1274
1334
val = _fitz .Page_addCircleAnnot (self , rect )
@@ -1283,7 +1343,7 @@ def addCircleAnnot(self, rect):
1283
1343
1284
1344
1285
1345
def addPolylineAnnot (self , points ):
1286
- """addPolylineAnnot(self, points) -> Annot """
1346
+ """Add a polyline annotation for a sequence of Points """
1287
1347
CheckParent (self )
1288
1348
1289
1349
val = _fitz .Page_addPolylineAnnot (self , points )
@@ -1298,7 +1358,7 @@ def addPolylineAnnot(self, points):
1298
1358
1299
1359
1300
1360
def addPolygonAnnot (self , points ):
1301
- """addPolygonAnnot(self, points) -> Annot """
1361
+ """Add a polygon annotation for a sequence of Points """
1302
1362
CheckParent (self )
1303
1363
1304
1364
val = _fitz .Page_addPolygonAnnot (self , points )
@@ -1313,7 +1373,7 @@ def addPolygonAnnot(self, points):
1313
1373
1314
1374
1315
1375
def addFreetextAnnot (self , pos , text , fontsize = 11 , color = None ):
1316
- """addFreetextAnnot(self, pos, text, fontsize=11, color=None) -> Annot """
1376
+ """Add a FreeText annotation at Point pos """
1317
1377
CheckParent (self )
1318
1378
1319
1379
val = _fitz .Page_addFreetextAnnot (self , pos , text , fontsize , color )
@@ -2443,6 +2503,19 @@ def __repr__(self):
2443
2503
ANNOT_LE_ROpenArrow = _fitz .ANNOT_LE_ROpenArrow
2444
2504
ANNOT_LE_RClosedArrow = _fitz .ANNOT_LE_RClosedArrow
2445
2505
ANNOT_LE_Slash = _fitz .ANNOT_LE_Slash
2506
+ ANNOT_WG_NOT_WIDGET = _fitz .ANNOT_WG_NOT_WIDGET
2507
+ ANNOT_WG_PUSHBUTTON = _fitz .ANNOT_WG_PUSHBUTTON
2508
+ ANNOT_WG_CHECKBOX = _fitz .ANNOT_WG_CHECKBOX
2509
+ ANNOT_WG_RADIOBUTTON = _fitz .ANNOT_WG_RADIOBUTTON
2510
+ ANNOT_WG_TEXT = _fitz .ANNOT_WG_TEXT
2511
+ ANNOT_WG_LISTBOX = _fitz .ANNOT_WG_LISTBOX
2512
+ ANNOT_WG_COMBOBOX = _fitz .ANNOT_WG_COMBOBOX
2513
+ ANNOT_WG_SIGNATURE = _fitz .ANNOT_WG_SIGNATURE
2514
+ ANNOT_WG_TEXT_UNRESTRAINED = _fitz .ANNOT_WG_TEXT_UNRESTRAINED
2515
+ ANNOT_WG_TEXT_NUMBER = _fitz .ANNOT_WG_TEXT_NUMBER
2516
+ ANNOT_WG_TEXT_SPECIAL = _fitz .ANNOT_WG_TEXT_SPECIAL
2517
+ ANNOT_WG_TEXT_DATE = _fitz .ANNOT_WG_TEXT_DATE
2518
+ ANNOT_WG_TEXT_TIME = _fitz .ANNOT_WG_TEXT_TIME
2446
2519
class Annot (_object ):
2447
2520
"""Proxy of C fz_annot_s struct."""
2448
2521
@@ -2690,6 +2763,32 @@ def getPixmap(self, matrix=None, colorspace=None, alpha=0):
2690
2763
return _fitz .Annot_getPixmap (self , matrix , colorspace , alpha )
2691
2764
2692
2765
2766
+ def _getWidget (self , Widget ):
2767
+ """_getWidget(self, Widget) -> PyObject *"""
2768
+ CheckParent (self )
2769
+
2770
+ return _fitz .Annot__getWidget (self , Widget )
2771
+
2772
+
2773
+ @property
2774
+ def widget (self ):
2775
+ annot_type = self .type [0 ]
2776
+ if annot_type != ANNOT_WIDGET :
2777
+ return None
2778
+ w = Widget ()
2779
+ w .field_type = self .widget_type [0 ]
2780
+ w .field_type_text = self .widget_type [1 ]
2781
+ w .field_value = self .widget_value
2782
+ w .field_name = self .widget_name
2783
+ w .list_values = self .widget_choices
2784
+ w .rect = self .rect
2785
+ self ._getWidget (w )
2786
+ return w
2787
+
2788
+ def updateWidget (self , widget ):
2789
+ widget ._validate ()
2790
+ self ._updateWidget (widget )
2791
+
2693
2792
def _erase (self ):
2694
2793
try :
2695
2794
self .parent ._forget_annot (self )
0 commit comments