pdf/src/form.rs#
Source: lib/pdf/src/form.rs
form -- the fields of an interactive form the writer makes (ISO 32000-1, 12.7): text fields,
check boxes, radio buttons, combo and list boxes, push buttons and empty signature fields,
each a widget on its page with its appearance streams (appear.rs), in the document's
AcroForm.
c.text_field(x, y, w, h, "person.name", &TextField { value: "Jakob", ..TextField::default() });
c.check_box(x, y, w, h, "agree", true, &FieldStyle::default());
c.radio(x, y, w, h, "size", "M", true, &style); // one name: one group of buttons
c.combo_box(x, y, w, h, "land", &["DE", "AT"], "DE", false, &style);
c.list_box(x, y, w, h, "colours", &["red", "blue"], &["blue"], false, &style);
c.push_button(x, y, w, h, "ok", "OK", Some("https://example.org/"), &style);
c.signature_field(x, y, w, h, "signature");
Names with dots make parent fields ("person.name" is the field "name" under "person"). A
name given to fields of two kinds, or both to a field and as a parent, a font that is not the
document's, a combo box's value that is none of its options (unless it is editable) make
write() fail (Error::Invalid). A radio button's on state is its place in its group ("0",
"1", ...) and its export value that place of the group's /Opt, so any text is an export
value; a check box's on state is /Yes. A widget keeps its border's width in /BS, so an
appearance made again has it; a comb is one line (with multiline or password, no comb).
Fonts: FieldStyle::font is Helvetica (one of the 14 standard fonts, WinAnsiEncoding, not
embedded; a character outside WinAnsi makes write() fail) or a font of the document, which is
then embedded in full (no subset tag, every glyph, the widths of every glyph) so a viewer can
set any text the font has. Size 0 is automatic. Check boxes and radio buttons draw
ZapfDingbats' check mark and dot. The form's /DA is "/Helv 0 Tf 0 g"; NeedAppearances is not
set, every widget has its appearance.
enum Alignhow a text field's lines sit (/Q)LeftCenterRight
enum FieldFontthe font of a field's textHelvetica-- the standard font Helvetica (WinAnsiEncoding, not embedded)Embedded(FontId)-- a font of the document, embedded in full
struct FieldStylewhat a field looks likeborder: Option<Rgb>-- the border's colour (None: no border) and widthborder_width: f64background: Option<Rgb>text: Rgbfont: FieldFontsize: f64-- points; 0 is automatic
struct TextField<'a>a text fieldvalue: &'a stralign: Alignmultiline: boolpassword: boolmax_len: Option<u32>comb: bool-- max_len cells of one character eachread_only: boolrequired: boolstyle: FieldStyle
impl Canvas<'_>
fn text_field(&mut self, x: f64, y: f64, w: f64, h: f64, name: &str, f: &TextField)a text field on the rectangle x, y, w, hfn check_box(&mut self, x: f64, y: f64, w: f64, h: f64, name: &str, checked: bool, style: &FieldStyle)a check box, checked or notfn radio(&mut self, x: f64, y: f64, w: f64, h: f64, name: &str, value: &str, selected: bool, style: &FieldStyle)a radio button of the groupnamewith the export valuevalue; the last one selected of a group is on. Its on state is its place in the group ("0", "1", ...), its export value that place of the group's /Opt (12.7.4.2.4), so any text is an export valuefn combo_box(&mut self, x: f64, y: f64, w: f64, h: f64, name: &str, options: &[&str], value: &str, editable: bool, style: &FieldStyle)a combo box: one of the options shown, typed text too when editablefn list_box(&mut self, x: f64, y: f64, w: f64, h: f64, name: &str, options: &[&str], selected: &[&str], multi: bool, style: &FieldStyle)a list box with the optionsselectedchosen (several only withmulti)fn signature_field(&mut self, x: f64, y: f64, w: f64, h: f64, name: &str)an empty signature field, to be signed later