File: PDFWidget.rst

package info (click to toggle)
mupdf 1.27.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,224 kB
  • sloc: ansic: 335,320; python: 20,906; java: 7,520; javascript: 2,213; makefile: 1,152; xml: 675; cpp: 639; sh: 513; cs: 307; awk: 10; sed: 7; lisp: 3
file content (468 lines) | stat: -rw-r--r-- 10,154 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
.. default-domain:: js

.. highlight:: javascript

PDFWidget
===================

:term:`Widgets <Widget Type>` are annotations that represent form
components such as buttons, text inputs and signature fields.

Because PDFWidget inherits `PDFAnnotation`, they also provide the
same interface as other annotation types.

Many widgets, e.g. text inputs or checkboxes, are the visual representation of
an associated form field. As the widget changes state, so does its
corresponding field value; for example when the text is edited in a text input
or a checkbox is checked. Note that widgets may be changed by Javascript event
handlers triggered by edits on other widgets.

The PDF specification has sections on `Widget annotations
<https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf#G13.1951506>`_
and
`Interactive forms
<https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf#G13.1951635>`_
with further details.

Constructors
------------

.. class:: PDFWidget

	|no_new|

To get the widgets on a page, see `PDFPage.prototype.getWidgets()`.

Instance methods
----------------

.. method:: PDFWidget.prototype.getFieldType()

	Return the widget type, one of the following:

	``"button" | "checkbox" | "combobox" | "listbox" | "radiobutton" | "signature" | "text"``

	:returns: string

	.. code-block::

		var type = widget.getFieldType()

.. method:: PDFWidget.prototype.getFieldFlags()

	Return the field flags which indicate attributes for the
	field. There are convenience functions to check some of these:
	:js:meth:`~PDFWidget.prototype.isReadOnly()`,
	:js:meth:`~PDFWidget.prototype.isMultiline()`,
	:js:meth:`~PDFWidget.prototype.isPassword()`,
	:js:meth:`~PDFWidget.prototype.isComb()`,
	:js:meth:`~PDFWidget.prototype.isButton()`,
	:js:meth:`~PDFWidget.prototype.isPushButton()`,
	:js:meth:`~PDFWidget.prototype.isCheckbox()`,
	:js:meth:`~PDFWidget.prototype.isRadioButton()`,
	:js:meth:`~PDFWidget.prototype.isText()`,
	:js:meth:`~PDFWidget.prototype.isChoice()`,
	:js:meth:`~PDFWidget.prototype.isListBox()`,
	and
	:js:meth:`~PDFWidget.prototype.isComboBox()`.

	For details refer to the PDF specification's sections
	on flags
	`common to all field types
	<https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf#G13.1697681>`_,
	`for button fields
	<https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf#G13.1697832>`_,
	`for text fields
	<https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf#G13.1967484>`_,
	and
	`for choice fields
	<https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf#G13.1873701>`_.

	:returns: number

	.. code-block::

		var flags = widget.getFieldFlags()

.. method:: PDFWidget.prototype.getName()

	Retrieve the name of the field.

	:returns: string

	.. code-block::

		var fieldName = widget.getName()

.. method:: PDFWidget.prototype.getMaxLen()

	Get maximum allowed length of the string value.

	:returns: number

	.. code-block::

		var length = widget.getMaxLen()

.. method:: PDFWidget.prototype.getOptions()

	Returns an array of strings which represent the value for each corresponding radio button or checkbox field.

	:returns: Array of string

	.. code-block::

		var options = widget.getOptions()

.. method:: PDFWidget.prototype.getLabel()

	Get the field name as a string.

	:returns: string

	.. code-block::

		var label = widget.getLabel()

Editing
-------

.. method:: PDFWidget.prototype.getValue()

	Get the widget value.

	:returns: string

	.. code-block::

		var value = widget.getValue()

.. method:: PDFWidget.prototype.setTextValue(value)

	Set the widget string value.

	:param string value: New text value.

	.. code-block::

		widget.setTextValue("Hello World!")

.. method:: PDFWidget.prototype.setChoiceValue(value)

	Sets the choice value against the widget.

	:param string value: New choice value.

	.. code-block::

		widget.setChoiceValue("Yes")

.. method:: PDFWidget.prototype.toggle()

	Toggle the state of the widget, returns true if the state changed.

	:returns: boolean

	.. code-block::

		var state = widget.toggle()

.. method:: PDFWidget.prototype.getEditingState()

	|only_mutool|

	Get whether the widget is in editing state.

	:returns: boolean

	.. code-block::

		var state = widget.getEditingState()

.. method:: PDFWidget.prototype.setEditingState(state)

	|only_mutool|

	Set whether the widget is in editing state.

	When in editing state any changes to the widget value will not
	cause any side-effects such as changing other widgets or
	running Javascript event handlers. This is intended for, e.g.
	when a text widget is interactively having characters typed
	into it. Once editing is finished the state should reverted
	back, before updating the widget value again.

	:param boolean state:

	.. code-block::

		widget.getEditingState(false)

.. TODO The text layout object needs to be described.

.. method:: PDFWidget.prototype.layoutTextWidget()

	|only_mutool|

	Layout the value of a text widget. Returns a text layout object.

	:returns: Object

	.. code-block::

		var layout = widget.layoutTextWidget()

Flags
-----

.. method:: PDFWidget.prototype.isReadOnly()

	If the value is read only and the widget cannot be interacted with.

	:returns: boolean

	.. code-block::

		var isReadOnly = widget.isReadOnly()

.. method:: PDFWidget.prototype.isMultiline()

	|only_mupdfjs|

	Return whether the widget is multi-line.

	:returns: boolean

.. method:: PDFWidget.prototype.isPassword()

	|only_mupdfjs|

	Return whether the widget is a password input.

	:returns: boolean

.. method:: PDFWidget.prototype.isComb()

	|only_mupdfjs|

	Return whether the widget is a text field laid out in "comb" style (forms where you write one character per square).

	:returns: boolean

.. method:: PDFWidget.prototype.isButton()

	|only_mupdfjs|

	Return whether the widget is of "button", "checkbox" or "radiobutton" type.

	:returns: boolean

.. method:: PDFWidget.prototype.isPushButton()

	|only_mupdfjs|

	Return whether the widget is of "button" type.

	:returns: boolean

.. method:: PDFWidget.prototype.isCheckbox()

	|only_mupdfjs|

	Return whether the widget is of "checkbox" type.

	:returns: boolean

.. method:: PDFWidget.prototype.isRadioButton()

	Return whether the widget is of "radiobutton" type.

	:returns: boolean

.. method:: PDFWidget.prototype.isText()

	|only_mupdfjs|

	Return whether the widget is of "text" type.

	:returns: boolean

.. method:: PDFWidget.prototype.isChoice()

	|only_mupdfjs|

	Return whether the widget is of "combobox" or "listbox" type.

	:returns: boolean

.. method:: PDFWidget.prototype.isListBox()

	|only_mupdfjs|

	Return whether the widget is of "listbox" type.

	:returns: boolean

.. method:: PDFWidget.prototype.isComboBox()

	|only_mupdfjs|

	Return whether the widget is of "combobox" type.

	:returns: boolean

Signatures
----------

.. method:: PDFWidget.prototype.isSigned()

	|only_mutool|

	Returns true if the signature is signed.

	:returns: boolean

	.. code-block::

		var isSigned = widget.isSigned()

.. method:: PDFWidget.prototype.validateSignature()

	|only_mutool|

	Returns number of updates ago when signature became invalid.
	Returns 0 is signature is still valid, 1 if it became
	invalid during the last save, etc.

	:returns: number

	.. code-block::

		var validNum = widget.validateSignature()

.. method:: PDFWidget.prototype.checkCertificate()

	|only_mutool|

	Returns "OK" if signature checked out OK, otherwise a text
	string containing an error message, e.g. "Self-signed
	certificate." or "Signature invalidated by change to
	document.", etc.

	:returns: string

	.. code-block::

		var result = widget.checkCertificate()

.. method:: PDFWidget.prototype.checkDigest()

	|only_mutool|

	Returns "OK" if digest checked out OK, otherwise a text string
	containing an error message.

	:returns: string

	.. code-block::

		var result = widget.checkDigest()

.. method:: PDFWidget.prototype.getSignatory()

	|only_mutool|

	Returns a text string with the distinguished name from a signed
	signature, or a text string with an error message.

	The returned string follows the format:

	``"cn=Name, o=Organization, ou=Organizational Unit,
	email=jane.doe@example.com, c=US"``

	:returns: string

	.. code-block::

		var signatory = widget.getSignatory()

.. TODO document what properties exist in the signatureConfig
.. TODO PDFPKCS7Signer... what do we do with this? mutool run has it, so better document it. maybe mupdf.js will gain PDF PKCS 7 digests in the future?

.. method:: PDFWidget.prototype.previewSignature(signer, signatureConfig, image, reason, location)

	|only_mutool|

	Return a `Pixmap` preview of what the signature would look like
	if signed with the given configuration. Reason and location may
	be ``undefined``, in which case they are not shown.

	:param PDFPKCS7Signer signer:
	:param Object signatureConfig:
	:param Image image:
	:param string reason:
	:param string location:

	:returns: Pixmap

	.. code-block::

		var pixmap = widget.previewSignature(
			signer,
			{
				showLabels: true,
				showDate: true
			},
			image,
			"",
			""
		)

.. method:: PDFWidget.prototype.sign(signer, signatureConfig, image, reason, location)

	|only_mutool|

	Sign the signature with the given configuration. Reason and
	location may be ``undefined``, in which case they are not shown.

	:param PDFPKCS7Signer signer:
	:param Object signatureConfig:
	:param Image image:
	:param string reason:
	:param string location:

	.. code-block::

		widget.sign(
			signer,
			{
				showLabels: true,
				showDate: true
			},
			image,
			"",
			""
		)

.. method:: PDFWidget.prototype.clearSignature()

	|only_mutool|

	Clear a signed signature, making it unsigned again.

	.. code-block::

		widget.clearSignature()

.. method:: PDFWidget.prototype.incrementalChangesSinceSigning()

	|only_mutool|

	Returns true if there have been incremental changes since the
	signature widget was signed.

	:returns: boolean

	.. code-block::

		var changed = widget.incrementalChangesSinceSigning()