mupdf
Loading...
Searching...
No Matches
form.h
Go to the documentation of this file.
1// Copyright (C) 2004-2025 Artifex Software, Inc.
2//
3// This file is part of MuPDF.
4//
5// MuPDF is free software: you can redistribute it and/or modify it under the
6// terms of the GNU Affero General Public License as published by the Free
7// Software Foundation, either version 3 of the License, or (at your option)
8// any later version.
9//
10// MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13// details.
14//
15// You should have received a copy of the GNU Affero General Public License
16// along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17//
18// Alternative licensing terms are available from the licensor.
19// For commercial licensing, see <https://www.artifex.com/> or contact
20// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21// CA 94129, USA, for further information.
22
23#ifndef MUPDF_PDF_FORM_H
24#define MUPDF_PDF_FORM_H
25
27#include "mupdf/pdf/document.h"
28
29/* Types of widget */
41
42/* Types of text widget content */
51
57
58/*
59 create a new signature widget on the specified page, with the
60 specified name.
61
62 The returns pdf_annot reference must be dropped by the caller.
63 This is a change from releases up to an including 1.18, where
64 the returned reference was owned by the page and did not need
65 to be freed by the caller.
66*/
68
70
72
73/*
74 get the maximum number of
75 characters permitted in a text widget
76*/
78
79/*
80 get the type of content
81 required by a text widget
82*/
84
85/*
86 get the list of options for a list box or combo box.
87
88 Returns the number of options and fills in their
89 names within the supplied array. Should first be called with a
90 NULL array to find out how big the array should be. If exportval
91 is true, then the export values will be returned and not the list
92 values if there are export values present.
93*/
94int pdf_choice_widget_options(fz_context *ctx, pdf_annot *tw, int exportval, const char *opts[]);
96
97/*
98 get the value of a choice widget.
99
100 Returns the number of options currently selected and fills in
101 the supplied array with their strings. Should first be called
102 with NULL as the array to find out how big the array need to
103 be. The filled in elements should not be freed by the caller.
104*/
105int pdf_choice_widget_value(fz_context *ctx, pdf_annot *tw, const char *opts[]);
106
107/*
108 set the value of a choice widget.
109
110 The caller should pass the number of options selected and an
111 array of their names
112*/
113void pdf_choice_widget_set_value(fz_context *ctx, pdf_annot *tw, int n, const char *opts[]);
114
116const char *pdf_choice_field_option(fz_context *ctx, pdf_obj *field, int exportval, int i);
117
120
121/* Field flags */
122enum
123{
124 /* All fields */
128
129 /* Text fields */
137
138 /* Button fields */
143
144 /* Choice fields */
151};
152
154void pdf_reset_form(fz_context *ctx, pdf_document *doc, pdf_obj *fields, int exclude);
155
157const char *pdf_field_type_string(fz_context *ctx, pdf_obj *field);
159
160/*
161 Retrieve the name for a field as a C string that
162 must be freed by the caller.
163*/
165const char *pdf_field_value(fz_context *ctx, pdf_obj *field);
166void pdf_create_field_name(fz_context *ctx, pdf_document *doc, const char *prefix, char *buf, size_t len);
167
169void pdf_field_set_border_style(fz_context *ctx, pdf_obj *field, const char *text);
170void pdf_field_set_button_caption(fz_context *ctx, pdf_obj *field, const char *text);
174void pdf_field_set_display(fz_context *ctx, pdf_obj *field, int d);
175const char *pdf_field_label(fz_context *ctx, pdf_obj *field);
177
178int pdf_set_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, const char *text, int ignore_trigger_events);
179
180/*
181 Update the text of a text widget.
182
183 The text is first validated by the Field/Keystroke event processing and accepted only if it passes.
184
185 The function returns whether validation passed.
186*/
187int pdf_set_text_field_value(fz_context *ctx, pdf_annot *widget, const char *value);
188int pdf_set_choice_field_value(fz_context *ctx, pdf_annot *widget, const char *value);
189int pdf_edit_text_field_value(fz_context *ctx, pdf_annot *widget, const char *value, const char *change, int *selStart, int *selEnd, char **newvalue);
190
191typedef struct
192{
193 char *cn;
194 char *o;
195 char *ou;
196 char *email;
197 char *c;
198}
200
213
214/* Increment the reference count for a signer object */
216
217/* Drop a reference for a signer object */
219
220/* Obtain the distinguished name information from a signer object */
222
223/* Predict the size of the digest. The actual digest returned by create_digest will be no greater in size */
225
226/* Create a signature based on ranges of bytes drawn from a stream */
227typedef int (pdf_pkcs7_create_digest_fn)(fz_context *ctx, pdf_pkcs7_signer *signer, fz_stream *in, unsigned char *digest, size_t digest_len);
228
237
239
241typedef pdf_signature_error (pdf_pkcs7_check_certificate_fn)(fz_context *ctx, pdf_pkcs7_verifier *verifier, unsigned char *signature, size_t len);
242typedef pdf_signature_error (pdf_pkcs7_check_digest_fn)(fz_context *ctx, pdf_pkcs7_verifier *verifier, fz_stream *in, unsigned char *signature, size_t len);
243typedef pdf_pkcs7_distinguished_name *(pdf_pkcs7_get_signatory_fn)(fz_context *ctx, pdf_pkcs7_verifier *verifier, unsigned char *signature, size_t len);
244
252
254void pdf_signature_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, pdf_pkcs7_signer *signer, int64_t stime);
255
257
259
264char *pdf_signature_info(fz_context *ctx, const char *name, pdf_pkcs7_distinguished_name *dn, const char *reason, const char *location, int64_t date, int include_labels);
265fz_display_list *pdf_signature_appearance_signed(fz_context *ctx, fz_rect rect, fz_text_language lang, fz_image *img, const char *left_text, const char *right_text, int include_logo);
267
272
274
275/*
276 Sign a signature field, while assigning it an arbitrary appearance determined by a display list.
277 The function pdf_signature_appearance can generate a variety of common signature appearances.
278*/
279void pdf_sign_signature_with_appearance(fz_context *ctx, pdf_annot *widget, pdf_pkcs7_signer *signer, int64_t date, fz_display_list *disp_list);
280
281enum {
288};
289
290#define PDF_SIGNATURE_DEFAULT_APPEARANCE ( \
291 PDF_SIGNATURE_SHOW_LABELS | \
292 PDF_SIGNATURE_SHOW_DN | \
293 PDF_SIGNATURE_SHOW_DATE | \
294 PDF_SIGNATURE_SHOW_TEXT_NAME | \
295 PDF_SIGNATURE_SHOW_GRAPHIC_NAME | \
296 PDF_SIGNATURE_SHOW_LOGO )
297
298/*
299 Sign a signature field, while assigning it a default appearance.
300*/
302 pdf_pkcs7_signer *signer,
303 int appearance_flags,
304 fz_image *graphic,
305 const char *reason,
306 const char *location);
307
308/*
309 Create a preview of the default signature appearance.
310*/
312 float w, float h, fz_text_language lang,
313 pdf_pkcs7_signer *signer,
314 int appearance_flags,
315 fz_image *graphic,
316 const char *reason,
317 const char *location);
318
320 int w, int h, fz_text_language lang,
321 pdf_pkcs7_signer *signer,
322 int appearance_flags,
323 fz_image *graphic,
324 const char *reason,
325 const char *location);
326
329
331
332pdf_obj *pdf_lookup_field(fz_context *ctx, pdf_obj *form, const char *name);
333
334/* Form text field editing events: */
335
336typedef struct
337{
338 const char *value;
339 const char *change;
343 char *newValue;
345
347int pdf_field_event_validate(fz_context *ctx, pdf_document *doc, pdf_obj *field, const char *value, char **newvalue);
350
352
353/* Call these to trigger actions from various UI events: */
354
360
363
374
375/*
376 * Bake appearances of annotations and/or widgets into static page content,
377 * and remove the corresponding interactive PDF objects.
378 */
379void pdf_bake_document(fz_context *ctx, pdf_document *doc, int bake_annots, int bake_widgets);
380
381#endif
struct pdf_annot pdf_annot
Definition annot.h:32
struct fz_display_list fz_display_list
Definition display-list.h:47
int pdf_widget_is_readonly(fz_context *ctx, pdf_annot *widget)
void pdf_annot_event_exit(fz_context *ctx, pdf_annot *annot)
void pdf_drop_verifier(fz_context *ctx, pdf_pkcs7_verifier *verifier)
void pdf_annot_event_blur(fz_context *ctx, pdf_annot *annot)
int pdf_choice_field_option_count(fz_context *ctx, pdf_obj *field)
pdf_pkcs7_signer * pdf_pkcs7_keep_signer_fn(fz_context *ctx, pdf_pkcs7_signer *signer)
Definition form.h:215
pdf_obj * pdf_button_field_on_state(fz_context *ctx, pdf_obj *field)
char * pdf_signature_info(fz_context *ctx, const char *name, pdf_pkcs7_distinguished_name *dn, const char *reason, const char *location, int64_t date, int include_labels)
pdf_signature_error pdf_check_widget_certificate(fz_context *ctx, pdf_pkcs7_verifier *verifier, pdf_annot *widget)
const char * pdf_field_label(fz_context *ctx, pdf_obj *field)
void pdf_create_field_name(fz_context *ctx, pdf_document *doc, const char *prefix, char *buf, size_t len)
const char * pdf_choice_field_option(fz_context *ctx, pdf_obj *field, int exportval, int i)
fz_pixmap * pdf_preview_signature_as_pixmap(fz_context *ctx, int w, int h, fz_text_language lang, pdf_pkcs7_signer *signer, int appearance_flags, fz_image *graphic, const char *reason, const char *location)
int pdf_text_widget_max_len(fz_context *ctx, pdf_annot *tw)
void pdf_sign_signature_with_appearance(fz_context *ctx, pdf_annot *widget, pdf_pkcs7_signer *signer, int64_t date, fz_display_list *disp_list)
int pdf_field_event_validate(fz_context *ctx, pdf_document *doc, pdf_obj *field, const char *value, char **newvalue)
fz_display_list * pdf_signature_appearance_unsigned(fz_context *ctx, fz_rect rect, fz_text_language lang)
void pdf_field_set_fill_color(fz_context *ctx, pdf_obj *field, pdf_obj *col)
char * pdf_field_event_format(fz_context *ctx, pdf_document *doc, pdf_obj *field)
pdf_pkcs7_distinguished_name * pdf_signature_get_widget_signatory(fz_context *ctx, pdf_pkcs7_verifier *verifier, pdf_annot *widget)
int pdf_widget_is_signed(fz_context *ctx, pdf_annot *widget)
void pdf_drop_widget(fz_context *ctx, pdf_annot *widget)
pdf_annot * pdf_create_signature_widget(fz_context *ctx, pdf_page *page, char *name)
char * pdf_load_field_name(fz_context *ctx, pdf_obj *field)
void pdf_calculate_form(fz_context *ctx, pdf_document *doc)
pdf_annot * pdf_next_widget(fz_context *ctx, pdf_annot *previous)
int pdf_choice_widget_is_multiselect(fz_context *ctx, pdf_annot *tw)
pdf_signature_error pdf_check_certificate(fz_context *ctx, pdf_pkcs7_verifier *verifier, pdf_document *doc, pdf_obj *signature)
char * pdf_signature_format_distinguished_name(fz_context *ctx, pdf_pkcs7_distinguished_name *name)
void pdf_bake_document(fz_context *ctx, pdf_document *doc, int bake_annots, int bake_widgets)
void pdf_drop_signer(fz_context *ctx, pdf_pkcs7_signer *signer)
int pdf_field_display(fz_context *ctx, pdf_obj *field)
pdf_signature_error
Definition form.h:202
@ PDF_SIGNATURE_ERROR_DIGEST_FAILURE
Definition form.h:206
@ PDF_SIGNATURE_ERROR_NOT_SIGNED
Definition form.h:210
@ PDF_SIGNATURE_ERROR_NOT_TRUSTED
Definition form.h:209
@ PDF_SIGNATURE_ERROR_SELF_SIGNED
Definition form.h:207
@ PDF_SIGNATURE_ERROR_NO_SIGNATURES
Definition form.h:204
@ PDF_SIGNATURE_ERROR_UNKNOWN
Definition form.h:211
@ PDF_SIGNATURE_ERROR_NO_CERTIFICATE
Definition form.h:205
@ PDF_SIGNATURE_ERROR_SELF_SIGNED_IN_CHAIN
Definition form.h:208
@ PDF_SIGNATURE_ERROR_OKAY
Definition form.h:203
void pdf_annot_event_page_open(fz_context *ctx, pdf_annot *annot)
int pdf_set_choice_field_value(fz_context *ctx, pdf_annot *widget, const char *value)
void pdf_field_set_display(fz_context *ctx, pdf_obj *field, int d)
int pdf_set_text_field_value(fz_context *ctx, pdf_annot *widget, const char *value)
void pdf_field_event_calculate(fz_context *ctx, pdf_document *doc, pdf_obj *field)
pdf_signature_error pdf_pkcs7_check_digest_fn(fz_context *ctx, pdf_pkcs7_verifier *verifier, fz_stream *in, unsigned char *signature, size_t len)
Definition form.h:242
pdf_pkcs7_distinguished_name * pdf_pkcs7_get_signing_name_fn(fz_context *ctx, pdf_pkcs7_signer *signer)
Definition form.h:221
void pdf_signature_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, pdf_pkcs7_signer *signer, int64_t stime)
void pdf_annot_event_page_invisible(fz_context *ctx, pdf_annot *annot)
pdf_annot * pdf_keep_widget(fz_context *ctx, pdf_annot *widget)
void pdf_pkcs7_drop_signer_fn(fz_context *ctx, pdf_pkcs7_signer *signer)
Definition form.h:218
void pdf_page_event_open(fz_context *ctx, pdf_page *page)
const char * pdf_field_value(fz_context *ctx, pdf_obj *field)
void pdf_pkcs7_drop_verifier_fn(fz_context *ctx, pdf_pkcs7_verifier *verifier)
Definition form.h:240
void pdf_document_event_did_save(fz_context *ctx, pdf_document *doc)
int pdf_text_widget_format(fz_context *ctx, pdf_annot *tw)
void pdf_field_set_border_style(fz_context *ctx, pdf_obj *field, const char *text)
void pdf_page_event_close(fz_context *ctx, pdf_page *page)
pdf_widget_tx_format
Definition form.h:44
@ PDF_WIDGET_TX_FORMAT_DATE
Definition form.h:48
@ PDF_WIDGET_TX_FORMAT_SPECIAL
Definition form.h:47
@ PDF_WIDGET_TX_FORMAT_NONE
Definition form.h:45
@ PDF_WIDGET_TX_FORMAT_NUMBER
Definition form.h:46
@ PDF_WIDGET_TX_FORMAT_TIME
Definition form.h:49
int pdf_edit_text_field_value(fz_context *ctx, pdf_annot *widget, const char *value, const char *change, int *selStart, int *selEnd, char **newvalue)
void pdf_field_reset(fz_context *ctx, pdf_document *doc, pdf_obj *field)
void pdf_annot_event_down(fz_context *ctx, pdf_annot *annot)
void pdf_annot_event_up(fz_context *ctx, pdf_annot *annot)
int pdf_field_event_keystroke(fz_context *ctx, pdf_document *doc, pdf_obj *field, pdf_keystroke_event *evt)
pdf_annot * pdf_first_widget(fz_context *ctx, pdf_page *page)
int pdf_update_widget(fz_context *ctx, pdf_annot *widget)
int pdf_choice_widget_options(fz_context *ctx, pdf_annot *tw, int exportval, const char *opts[])
char * pdf_signature_error_description(pdf_signature_error err)
void pdf_signature_drop_distinguished_name(fz_context *ctx, pdf_pkcs7_distinguished_name *name)
int pdf_count_signatures(fz_context *ctx, pdf_document *doc)
void pdf_clear_signature(fz_context *ctx, pdf_annot *widget)
void pdf_document_event_will_print(fz_context *ctx, pdf_document *doc)
pdf_pkcs7_distinguished_name * pdf_signature_get_signatory(fz_context *ctx, pdf_pkcs7_verifier *verifier, pdf_document *doc, pdf_obj *signature)
fz_display_list * pdf_signature_appearance_signed(fz_context *ctx, fz_rect rect, fz_text_language lang, fz_image *img, const char *left_text, const char *right_text, int include_logo)
pdf_signature_error pdf_pkcs7_check_certificate_fn(fz_context *ctx, pdf_pkcs7_verifier *verifier, unsigned char *signature, size_t len)
Definition form.h:241
void pdf_reset_form(fz_context *ctx, pdf_document *doc, pdf_obj *fields, int exclude)
fz_display_list * pdf_preview_signature_as_display_list(fz_context *ctx, float w, float h, fz_text_language lang, pdf_pkcs7_signer *signer, int appearance_flags, fz_image *graphic, const char *reason, const char *location)
pdf_obj * pdf_lookup_field(fz_context *ctx, pdf_obj *form, const char *name)
int pdf_field_flags(fz_context *ctx, pdf_obj *field)
void pdf_annot_event_page_close(fz_context *ctx, pdf_annot *annot)
size_t pdf_pkcs7_max_digest_size_fn(fz_context *ctx, pdf_pkcs7_signer *signer)
Definition form.h:224
const char * pdf_field_type_string(fz_context *ctx, pdf_obj *field)
void pdf_annot_event_page_visible(fz_context *ctx, pdf_annot *annot)
void pdf_document_event_will_close(fz_context *ctx, pdf_document *doc)
int pdf_annot_field_event_keystroke(fz_context *ctx, pdf_document *doc, pdf_annot *annot, pdf_keystroke_event *evt)
pdf_pkcs7_distinguished_name * pdf_pkcs7_get_signatory_fn(fz_context *ctx, pdf_pkcs7_verifier *verifier, unsigned char *signature, size_t len)
Definition form.h:243
@ PDF_SIGNATURE_SHOW_LABELS
Definition form.h:282
@ PDF_SIGNATURE_SHOW_TEXT_NAME
Definition form.h:285
@ PDF_SIGNATURE_SHOW_DATE
Definition form.h:284
@ PDF_SIGNATURE_SHOW_LOGO
Definition form.h:287
@ PDF_SIGNATURE_SHOW_GRAPHIC_NAME
Definition form.h:286
@ PDF_SIGNATURE_SHOW_DN
Definition form.h:283
char * pdf_field_border_style(fz_context *ctx, pdf_obj *field)
fz_rect pdf_bound_widget(fz_context *ctx, pdf_annot *widget)
void pdf_sign_signature(fz_context *ctx, pdf_annot *widget, pdf_pkcs7_signer *signer, int appearance_flags, fz_image *graphic, const char *reason, const char *location)
pdf_widget_type
Definition form.h:31
@ PDF_WIDGET_TYPE_SIGNATURE
Definition form.h:38
@ PDF_WIDGET_TYPE_TEXT
Definition form.h:39
@ PDF_WIDGET_TYPE_CHECKBOX
Definition form.h:34
@ PDF_WIDGET_TYPE_RADIOBUTTON
Definition form.h:37
@ PDF_WIDGET_TYPE_UNKNOWN
Definition form.h:32
@ PDF_WIDGET_TYPE_COMBOBOX
Definition form.h:35
@ PDF_WIDGET_TYPE_LISTBOX
Definition form.h:36
@ PDF_WIDGET_TYPE_BUTTON
Definition form.h:33
void pdf_choice_widget_set_value(fz_context *ctx, pdf_annot *tw, int n, const char *opts[])
pdf_signature_error pdf_check_digest(fz_context *ctx, pdf_pkcs7_verifier *verifier, pdf_document *doc, pdf_obj *signature)
void pdf_field_set_text_color(fz_context *ctx, pdf_obj *field, pdf_obj *col)
int pdf_pkcs7_create_digest_fn(fz_context *ctx, pdf_pkcs7_signer *signer, fz_stream *in, unsigned char *digest, size_t digest_len)
Definition form.h:227
int pdf_signature_is_signed(fz_context *ctx, pdf_document *doc, pdf_obj *field)
int pdf_set_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, const char *text, int ignore_trigger_events)
void pdf_field_set_button_caption(fz_context *ctx, pdf_obj *field, const char *text)
@ PDF_TX_FIELD_IS_COMB
Definition form.h:135
@ PDF_FIELD_IS_REQUIRED
Definition form.h:126
@ PDF_TX_FIELD_IS_MULTILINE
Definition form.h:130
@ PDF_TX_FIELD_IS_FILE_SELECT
Definition form.h:132
@ PDF_FIELD_IS_NO_EXPORT
Definition form.h:127
@ PDF_TX_FIELD_IS_DO_NOT_SPELL_CHECK
Definition form.h:133
@ PDF_CH_FIELD_IS_MULTI_SELECT
Definition form.h:148
@ PDF_BTN_FIELD_IS_RADIO
Definition form.h:140
@ PDF_CH_FIELD_IS_DO_NOT_SPELL_CHECK
Definition form.h:149
@ PDF_CH_FIELD_IS_COMBO
Definition form.h:145
@ PDF_TX_FIELD_IS_RICH_TEXT
Definition form.h:136
@ PDF_BTN_FIELD_IS_RADIOS_IN_UNISON
Definition form.h:142
@ PDF_BTN_FIELD_IS_NO_TOGGLE_TO_OFF
Definition form.h:139
@ PDF_CH_FIELD_IS_EDIT
Definition form.h:146
@ PDF_FIELD_IS_READ_ONLY
Definition form.h:125
@ PDF_TX_FIELD_IS_DO_NOT_SCROLL
Definition form.h:134
@ PDF_CH_FIELD_IS_COMMIT_ON_SEL_CHANGE
Definition form.h:150
@ PDF_CH_FIELD_IS_SORT
Definition form.h:147
@ PDF_BTN_FIELD_IS_PUSHBUTTON
Definition form.h:141
@ PDF_TX_FIELD_IS_PASSWORD
Definition form.h:131
pdf_signature_error pdf_check_widget_digest(fz_context *ctx, pdf_pkcs7_verifier *verifier, pdf_annot *widget)
void pdf_document_event_did_print(fz_context *ctx, pdf_document *doc)
void pdf_annot_event_focus(fz_context *ctx, pdf_annot *annot)
void pdf_document_event_will_save(fz_context *ctx, pdf_document *doc)
int pdf_choice_widget_value(fz_context *ctx, pdf_annot *tw, const char *opts[])
void pdf_annot_event_enter(fz_context *ctx, pdf_annot *annot)
int pdf_field_type(fz_context *ctx, pdf_obj *field)
struct pdf_obj pdf_obj
Definition object.h:44
Definition context.h:886
Definition image.h:351
Definition pixmap.h:432
Definition geometry.h:231
Definition stream.h:320
Definition document.h:463
Definition form.h:337
const char * change
Definition form.h:339
int selEnd
Definition form.h:340
char * newValue
Definition form.h:343
int willCommit
Definition form.h:341
const char * value
Definition form.h:338
int selStart
Definition form.h:340
char * newChange
Definition form.h:342
Definition page.h:320
Definition form.h:192
char * c
Definition form.h:197
char * ou
Definition form.h:195
char * cn
Definition form.h:193
char * email
Definition form.h:196
char * o
Definition form.h:194
Definition form.h:230
pdf_pkcs7_get_signing_name_fn * get_signing_name
Definition form.h:233
pdf_pkcs7_create_digest_fn * create_digest
Definition form.h:235
pdf_pkcs7_drop_signer_fn * drop
Definition form.h:232
pdf_pkcs7_max_digest_size_fn * max_digest_size
Definition form.h:234
pdf_pkcs7_keep_signer_fn * keep
Definition form.h:231
Definition form.h:246
pdf_pkcs7_check_digest_fn * check_digest
Definition form.h:249
pdf_pkcs7_check_certificate_fn * check_certificate
Definition form.h:248
pdf_pkcs7_get_signatory_fn * get_signatory
Definition form.h:250
pdf_pkcs7_drop_verifier_fn * drop
Definition form.h:247
fz_text_language
Definition text.h:57