NAME
PDF::Make::Field - PDF form field for PDF::Make
SYNOPSIS
use PDF::Make;
my $pdf = PDF::Make->new();
my $page = $pdf->add_page(width => 612, height => 792);
my $form = $pdf->create_form();
# Create and configure a text field
my $field = $form->add_text_field(
name => 'name',
x => 100,
y => 700,
width => 200,
height => 20,
);
# Set properties
$field->set_value('John Doe');
$field->readonly(1);
$field->align_center();
# Add to page
$field->add_to_page($page);
DESCRIPTION
This class represents a PDF form field. Fields are created via the PDF::Make::Form methods like add_text_field, add_checkbox, etc.
METHODS
type
my $type = $field->type();
Return the field type as a string: 'text', 'button', 'choice', or 'signature'.
name
my $name = $field->name();
Return the partial field name.
full_name
my $full_name = $field->full_name();
Return the full field name (includes parent hierarchy).
value
my $value = $field->value();
$field->value('new value');
Get or set the field value.
set_value
$field->set_value('value');
Set the field value.
set_default_value
$field->set_default_value('default');
Set the default value (used when form is reset).
flags
my $flags = $field->flags();
Return the field flags as an integer.
set_flags
$field->set_flags($flags);
Set the field flags (replaces existing).
add_flags
$field->add_flags($flags);
Add flags to the existing set.
clear_flags
$field->clear_flags($flags);
Clear specific flags.
readonly
$field->readonly(1); # Make read-only
$field->readonly(0); # Make editable
my $ro = $field->readonly(); # Alias for is_readonly
Set or check the read-only flag.
is_readonly
if ($field->is_readonly()) { ... }
Check if field is read-only.
required
$field->required(1); # Mark as required
$field->required(0); # Mark as optional
my $req = $field->required(); # Alias for is_required
Set or check the required flag.
is_required
if ($field->is_required()) { ... }
Check if field is required.
noexport
$field->noexport(1);
Set the no-export flag (field value not included in FDF export).
multiline
$field->multiline(1);
Enable multiline text input (text fields only).
password
$field->password(1);
Enable password masking (text fields only).
set_da
$field->set_da('/Helv 12 Tf 0 g');
Set the default appearance string (font, size, color).
set_quadding
$field->set_quadding(0); # Left
$field->set_quadding(1); # Center
$field->set_quadding(2); # Right
Set text alignment.
align_left
$field->align_left();
Set left text alignment.
align_center
$field->align_center();
Set center text alignment.
align_right
$field->align_right();
Set right text alignment.
set_max_len
$field->set_max_len(100);
Set maximum character length (text fields only).
add_option
$field->add_option('Display Text');
$field->add_option('Display Text', 'export_value');
Add an option to a choice field.
option_count
my $count = $field->option_count();
Return the number of options (choice fields only).
options
my @opts = $field->options();
Return all options as a list of hashrefs with 'display' and 'export' keys.
add_radio_option
$group->add_radio_option(
x => 100,
y => 500,
width => 15,
height => 15,
value => 'Option1',
);
Add a radio button option to a radio group. Returns the option field.
add_to_page
$field->add_to_page($page);
Add the field's widget annotation to a page. This makes the field visible.
generate_appearance
$field->generate_appearance();
Generate the appearance stream for this field.
flatten
$field->flatten();
Flatten this field: render its value into page content and remove it.
parent
my $parent = $field->parent();
Return the parent field (for hierarchical fields).
children
my @children = $field->children();
Return child fields (for hierarchical fields).
has_children
if ($field->has_children()) { ... }
Check if field has children.
SEE ALSO
AUTHOR
LNATION <email@lnation.org>
COPYRIGHT AND LICENSE
Copyright (C) 2024 by LNATION
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.