blib/lib/PDF/Make/Form.pm

filter: Statementstmt 99.3% 153 / 154 Branchbran 100% 42 / 42 Conditioncond 97.9% 48 / 49 MC/DCmcdc 92.0% 23 / 25 Subroutinesub 96.4% 27 / 28 Podpod 100% 20 / 20 totaltotal 98.4% 313 / 318 CC 47 SCAR 17.6
CC
47
Cov
99%
add_choice
11.0
_configure_field
10.0
add_button
7.0
CRAP 5.8
« blib/lib/PDF/Make/Builder/Runs.pm ↑ Summary blib/lib/PDF/Make/Builder/Shape/Line.pm »
1 package PDF::Make::Form;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶no warnings qw(redefine prototype); # XS methods are overridden by Perl wrappers
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use PDF::Make;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use PDF::Make::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =encoding utf8
10  
11 =head1 NAME
12  
13 PDF::Make::Form - PDF interactive forms (AcroForms) for PDF::Make
14  
15 =head1 SYNOPSIS
16  
17 use PDF::Make;
18
19 my $pdf = PDF::Make->new();
20 my $page = $pdf->add_page(width => 612, height => 792);
21
22 # Create a form
23 my $form = $pdf->create_form();
24
25 # Add a text field
26 my $name_field = $form->add_text_field(
27 name => 'name',
28 x => 100,
29 y => 700,
30 width => 200,
31 height => 20,
32 );
33 $name_field->set_value('John Doe');
34 $name_field->add_to_page($page);
35
36 # Add a checkbox
37 my $checkbox = $form->add_checkbox(
38 name => 'agree',
39 x => 100,
40 y => 650,
41 width => 15,
42 height => 15,
43 on_value => 'Yes',
44 );
45 $checkbox->set_value('Yes'); # Check it
46 $checkbox->add_to_page($page);
47
48 # Finalize and render
49 $form->finalize();
50 my $bytes = $pdf->render();
51  
52 =head1 DESCRIPTION
53  
54 This module provides PDF interactive forms (AcroForms) support per
55 ISO 32000-2:2020 ยง12.7. It supports:
56  
57 =over 4
58  
59 =item * Text fields (single-line, multiline, password)
60  
61 =item * Checkboxes and radio button groups
62  
63 =item * Dropdown (combo) and list boxes
64  
65 =item * Push buttons
66  
67 =item * Signature fields (placeholder)
68  
69 =item * FDF/XFDF export and import
70  
71 =item * Form flattening
72  
73 =back
74  
75 =head1 METHODS
76  
77 =cut
78  
79 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
80 # Field flags (matching C header)
81 3 FF_READONLY => (1 << 0),
82 FF_REQUIRED => (1 << 1),
83 FF_NOEXPORT => (1 << 2),
84 FF_MULTILINE => (1 << 12),
85 FF_PASSWORD => (1 << 13),
86 FF_FILESELECT => (1 << 20),
87 FF_DONOTSPELLCHECK => (1 << 22),
88 FF_DONOTSCROLL => (1 << 23),
89 FF_COMB => (1 << 24),
90 FF_RICHTEXT => (1 << 25),
91 FF_NOTOGGLETOOFF => (1 << 14),
92 FF_RADIO => (1 << 15),
93 FF_PUSHBUTTON => (1 << 16),
94 FF_RADIOSINUNISON => (1 << 25),
95 FF_COMBO => (1 << 17),
96 FF_EDIT => (1 << 18),
97 FF_SORT => (1 << 19),
98 FF_MULTISELECT => (1 << 21),
99 FF_COMMITONSELCHANGE => (1 << 26),
100
101 # Quadding (text alignment)
102 QUADDING_LEFT => 0,
103 QUADDING_CENTER => 1,
104 QUADDING_RIGHT => 2,
105 3 };
106  
107 3 our @EXPORT_OK = qw(
108 FF_READONLY FF_REQUIRED FF_NOEXPORT
109 FF_MULTILINE FF_PASSWORD FF_FILESELECT FF_DONOTSPELLCHECK
110 FF_DONOTSCROLL FF_COMB FF_RICHTEXT
111 FF_NOTOGGLETOOFF FF_RADIO FF_PUSHBUTTON FF_RADIOSINUNISON
112 FF_COMBO FF_EDIT FF_SORT FF_MULTISELECT FF_COMMITONSELCHANGE
113 QUADDING_LEFT QUADDING_CENTER QUADDING_RIGHT
114 );
115  
116 3 our %EXPORT_TAGS = (
117 flags => [qw(FF_READONLY FF_REQUIRED FF_NOEXPORT FF_MULTILINE
118 FF_PASSWORD FF_COMB FF_COMBO FF_EDIT FF_MULTISELECT)],
119 quadding => [qw(QUADDING_LEFT QUADDING_CENTER QUADDING_RIGHT)],
120 all => \@EXPORT_OK,
121 );
122  
123 =head2 new
124  
125 my $form = PDF::Make::Form->new($document);
126  
127 Create a new form for the given document. Usually called via
128 C<< $pdf->create_form() >> rather than directly.
129  
130 =cut
131  
132 44 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
133 44 my ($class, $doc) = @_;
134
135 44 ▶ die "PDF::Make::Form->new: document required" unless $doc;
Branch: 1 branch
BranchTrueFalseTotal
unless $doc 1 43 44
136
137 # $doc is the raw pdfmake_doc_t pointer (Document object)
138 43 my $form = PDF::Make::FormPtr::create($doc);
139
140 43 return bless {
141 _form => $form,
142 _doc => $doc,
143 _fields => [],
144 }, $class;
145 }
146  
147 =head2 add_text_field
148  
149 my $field = $form->add_text_field(
150 name => 'field_name',
151 x => 100,
152 y => 500,
153 width => 200,
154 height => 20,
155 );
156  
157 Create a text field at the specified location.
158  
159 Options:
160  
161 =over 4
162  
163 =item * name - Field name (required)
164  
165 =item * x, y - Lower-left corner coordinates
166  
167 =item * width, height - Field dimensions
168  
169 =item * value - Initial value
170  
171 =item * default_value - Default value for reset
172  
173 =item * max_len - Maximum characters allowed
174  
175 =item * multiline - Enable multiline input
176  
177 =item * password - Mask input as password
178  
179 =item * readonly - Make field read-only
180  
181 =item * required - Mark as required
182  
183 =item * quadding - Text alignment (0=left, 1=center, 2=right)
184  
185 =item * da - Default appearance string
186  
187 =back
188  
189 =cut
190  
191 38 ▶sub add_text_field {
Subroutine add_text_field: called CC=6 SCAR=17.9
Pod documented
192 38 my ($self, %opts) = @_;
193
194 38 ▶ my $name = delete $opts{name} or die "add_text_field: name required";
Branch: 1 branch
BranchTrueFalseTotal
my $name = delete $opts{"name"} or die "add_text_field: name required" 37 1 38
195 37 ▶ my $x = delete $opts{x} // 0;
Condition100%2/2
delete $opts{"x"} // 0
l!l
343
MC/DC100%1/1
delete $opts{"x"} // 0
delete $opts{"x"}
Truth table100%2/2
A
A= delete $opts{"x"}
Aresult
11
00
196 37 ▶ my $y = delete $opts{y} // 0;
Condition100%2/2
delete $opts{"y"} // 0
l!l
343
MC/DC100%1/1
delete $opts{"y"} // 0
delete $opts{"y"}
Truth table100%2/2
A
A= delete $opts{"y"}
Aresult
11
00
197 37 ▶ my $width = delete $opts{width} // 100;
Condition100%2/2
delete $opts{"width"} // 100
l!l
289
MC/DC100%1/1
delete $opts{"width"} // 100
delete $opts{"width"}
Truth table100%2/2
A
A= delete $opts{"width"}
Aresult
11
00
198 37 ▶ my $height = delete $opts{height} // 20;
Condition100%2/2
delete $opts{"height"} // 20
l!l
289
MC/DC100%1/1
delete $opts{"height"} // 20
delete $opts{"height"}
Truth table100%2/2
A
A= delete $opts{"height"}
Aresult
11
00
199
200 my $field = PDF::Make::FieldPtr::text(
201 37 $self->{_doc}, $name, $x, $y, $width, $height
202 );
203
204 37 $self->_configure_field($field, %opts);
205
206 37 push @{$self->{_fields}}, $field;
207
208 37 return PDF::Make::Field->_wrap($field, $self);
209 }
210  
211 =head2 add_checkbox
212  
213 my $field = $form->add_checkbox(
214 name => 'agree',
215 x => 100,
216 y => 500,
217 width => 15,
218 height => 15,
219 on_value => 'Yes',
220 );
221  
222 Create a checkbox field.
223  
224 =cut
225  
226 6 ▶sub add_checkbox {
Subroutine add_checkbox: called CC=7 SCAR=19.5
Pod documented
227 6 my ($self, %opts) = @_;
228
229 6 ▶ my $name = delete $opts{name} or die "add_checkbox: name required";
Branch: 1 branch
BranchTrueFalseTotal
my $name = delete $opts{"name"} or die "add_checkbox: name required" 5 1 6
230 5 ▶ my $x = delete $opts{x} // 0;
Condition100%2/2
delete $opts{"x"} // 0
l!l
41
MC/DC100%1/1
delete $opts{"x"} // 0
delete $opts{"x"}
Truth table100%2/2
A
A= delete $opts{"x"}
Aresult
11
00
231 5 ▶ my $y = delete $opts{y} // 0;
Condition100%2/2
delete $opts{"y"} // 0
l!l
41
MC/DC100%1/1
delete $opts{"y"} // 0
delete $opts{"y"}
Truth table100%2/2
A
A= delete $opts{"y"}
Aresult
11
00
232 5 ▶ my $width = delete $opts{width} // 15;
Condition100%2/2
delete $opts{"width"} // 15
l!l
41
MC/DC100%1/1
delete $opts{"width"} // 15
delete $opts{"width"}
Truth table100%2/2
A
A= delete $opts{"width"}
Aresult
11
00
233 5 ▶ my $height = delete $opts{height} // 15;
Condition100%2/2
delete $opts{"height"} // 15
l!l
41
MC/DC100%1/1
delete $opts{"height"} // 15
delete $opts{"height"}
Truth table100%2/2
A
A= delete $opts{"height"}
Aresult
11
00
234 5 ▶ my $on_value = delete $opts{on_value} // 'Yes';
Condition100%2/2
delete $opts{"on_value"} // "Yes"
l!l
23
MC/DC100%1/1
delete $opts{"on_value"} // "Yes"
delete $opts{"on_value"}
Truth table100%2/2
A
A= delete $opts{"on_value"}
Aresult
11
00
235
236 my $field = PDF::Make::FieldPtr::checkbox(
237 5 $self->{_doc}, $name, $x, $y, $width, $height, $on_value
238 );
239
240 5 $self->_configure_field($field, %opts);
241
242 5 push @{$self->{_fields}}, $field;
243
244 5 return PDF::Make::Field->_wrap($field, $self);
245 }
246  
247 =head2 add_radio_group
248  
249 my $group = $form->add_radio_group(name => 'choice');
250 $group->add_option(x => 100, y => 500, width => 15, height => 15, value => 'A');
251 $group->add_option(x => 100, y => 480, width => 15, height => 15, value => 'B');
252 $group->add_option(x => 100, y => 460, width => 15, height => 15, value => 'C');
253  
254 Create a radio button group.
255  
256 =cut
257  
258 6 ▶sub add_radio_group {
Subroutine add_radio_group: called CC=2 SCAR=6.9
Pod documented
259 6 my ($self, %opts) = @_;
260
261 6 ▶ my $name = delete $opts{name} or die "add_radio_group: name required";
Branch: 1 branch
BranchTrueFalseTotal
my $name = delete $opts{"name"} or die "add_radio_group: name required" 5 1 6
262
263 5 my $group = PDF::Make::FieldPtr::radio_group($self->{_doc}, $name);
264
265 5 push @{$self->{_fields}}, $group;
266
267 5 return PDF::Make::Field->_wrap($group, $self);
268 }
269  
270 =head2 add_choice
271  
272 my $field = $form->add_choice(
273 name => 'country',
274 x => 100,
275 y => 500,
276 width => 150,
277 height => 20,
278 combo => 1, # 1 for dropdown, 0 for listbox
279 options => [
280 { display => 'United States', export => 'US' },
281 { display => 'Canada', export => 'CA' },
282 { display => 'Mexico', export => 'MX' },
283 ],
284 );
285  
286 Create a choice field (dropdown or listbox).
287  
288 =cut
289  
290 7 ▶sub add_choice {
Subroutine add_choice: called CC=11 SCAR=24.0
Pod documented
291 7 my ($self, %opts) = @_;
292
293 7 ▶ my $name = delete $opts{name} or die "add_choice: name required";
Branch: 1 branch
BranchTrueFalseTotal
my $name = delete $opts{"name"} or die "add_choice: name required" 6 1 7
294 6 ▶ my $x = delete $opts{x} // 0;
Condition100%2/2
delete $opts{"x"} // 0
l!l
42
MC/DC100%1/1
delete $opts{"x"} // 0
delete $opts{"x"}
Truth table100%2/2
A
A= delete $opts{"x"}
Aresult
11
00
295 6 ▶ my $y = delete $opts{y} // 0;
Condition100%2/2
delete $opts{"y"} // 0
l!l
42
MC/DC100%1/1
delete $opts{"y"} // 0
delete $opts{"y"}
Truth table100%2/2
A
A= delete $opts{"y"}
Aresult
11
00
296 6 ▶ my $width = delete $opts{width} // 100;
Condition100%2/2
delete $opts{"width"} // 100
l!l
42
MC/DC100%1/1
delete $opts{"width"} // 100
delete $opts{"width"}
Truth table100%2/2
A
A= delete $opts{"width"}
Aresult
11
00
297 6 ▶ my $height = delete $opts{height} // 20;
Condition100%2/2
delete $opts{"height"} // 20
l!l
42
MC/DC100%1/1
delete $opts{"height"} // 20
delete $opts{"height"}
Truth table100%2/2
A
A= delete $opts{"height"}
Aresult
11
00
298 6 ▶ my $combo = delete $opts{combo} // 1;
Condition100%2/2
delete $opts{"combo"} // 1
l!l
42
MC/DC100%1/1
delete $opts{"combo"} // 1
delete $opts{"combo"}
Truth table100%2/2
A
A= delete $opts{"combo"}
Aresult
11
00
299 6 ▶ my $options = delete $opts{options} // [];
Condition100%2/2
delete $opts{"options"} // []
l!l
33
MC/DC100%1/1
delete $opts{"options"} // []
delete $opts{"options"}
Truth table100%2/2
A
A= delete $opts{"options"}
Aresult
11
00
300
301 my $field = PDF::Make::FieldPtr::choice(
302 6 $self->{_doc}, $name, $x, $y, $width, $height, $combo
303 );
304
305 # Add options
306 6 for my $opt (@$options) {
307 10 ▶ if (ref $opt eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opt eq 'HASH') { } 4 6 10
308 4 my $display = $opt->{display};
309 4 my $export = $opt->{export};
310 4 ▶ if (defined $export) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $export) { } 3 1 4
311 3 $field->add_option($display, $export);
312 } else {
313 1 $field->add_option($display);
314 }
315 } else {
316 6 $field->add_option($opt);
317 }
318 }
319
320 6 $self->_configure_field($field, %opts);
321
322 6 push @{$self->{_fields}}, $field;
323
324 6 return PDF::Make::Field->_wrap($field, $self);
325 }
326  
327 =head2 add_combo
328  
329 my $field = $form->add_combo(name => 'country', ...);
330  
331 Shorthand for C<add_choice(combo => 1, ...)>.
332  
333 =cut
334  
335 2 ▶sub add_combo {
Subroutine add_combo: called CC=1 SCAR=0.0
Pod documented
336 2 my ($self, %opts) = @_;
337 2 return $self->add_choice(%opts, combo => 1);
338 }
339  
340 =head2 add_listbox
341  
342 my $field = $form->add_listbox(name => 'items', ...);
343  
344 Shorthand for C<add_choice(combo => 0, ...)>.
345  
346 =cut
347  
348 2 ▶sub add_listbox {
Subroutine add_listbox: called CC=1 SCAR=0.0
Pod documented
349 2 my ($self, %opts) = @_;
350 2 return $self->add_choice(%opts, combo => 0);
351 }
352  
353 =head2 add_button
354  
355 my $field = $form->add_button(
356 name => 'submit',
357 x => 100,
358 y => 100,
359 width => 80,
360 height => 25,
361 caption => 'Submit',
362 );
363  
364 Create a push button.
365  
366 =cut
367  
368 6 ▶sub add_button {
Subroutine add_button: called CC=7 SCAR=19.5
Pod documented
369 6 my ($self, %opts) = @_;
370
371 6 ▶ my $name = delete $opts{name} or die "add_button: name required";
Branch: 1 branch
BranchTrueFalseTotal
my $name = delete $opts{"name"} or die "add_button: name required" 5 1 6
372 5 ▶ my $x = delete $opts{x} // 0;
Condition100%2/2
delete $opts{"x"} // 0
l!l
32
MC/DC100%1/1
delete $opts{"x"} // 0
delete $opts{"x"}
Truth table100%2/2
A
A= delete $opts{"x"}
Aresult
11
00
373 5 ▶ my $y = delete $opts{y} // 0;
Condition100%2/2
delete $opts{"y"} // 0
l!l
32
MC/DC100%1/1
delete $opts{"y"} // 0
delete $opts{"y"}
Truth table100%2/2
A
A= delete $opts{"y"}
Aresult
11
00
374 5 ▶ my $width = delete $opts{width} // 80;
Condition100%2/2
delete $opts{"width"} // 80
l!l
32
MC/DC100%1/1
delete $opts{"width"} // 80
delete $opts{"width"}
Truth table100%2/2
A
A= delete $opts{"width"}
Aresult
11
00
375 5 ▶ my $height = delete $opts{height} // 25;
Condition100%2/2
delete $opts{"height"} // 25
l!l
32
MC/DC100%1/1
delete $opts{"height"} // 25
delete $opts{"height"}
Truth table100%2/2
A
A= delete $opts{"height"}
Aresult
11
00
376 5 ▶ my $caption = delete $opts{caption} // $name;
Condition66%2/3
delete $opts{"caption"} // $name
l!l&&r!l&&!r
410
MC/DC0%0/2
delete $opts{"caption"} // $name
delete $opts{"caption"} $name
Truth table66%2/3
A // B
A= delete $opts{"caption"}B= $name
ABresult
1X1
011
000
377
378 my $field = PDF::Make::FieldPtr::button(
379 5 $self->{_doc}, $name, $x, $y, $width, $height, $caption
380 );
381
382 5 $self->_configure_field($field, %opts);
383
384 5 push @{$self->{_fields}}, $field;
385
386 5 return PDF::Make::Field->_wrap($field, $self);
387 }
388  
389 =head2 add_signature
390  
391 my $field = $form->add_signature(
392 name => 'sig',
393 x => 100,
394 y => 100,
395 width => 200,
396 height => 50,
397 );
398  
399 Create a signature field (placeholder for digital signature).
400  
401 =cut
402  
403 4 ▶sub add_signature {
Subroutine add_signature: called CC=6 SCAR=17.9
Pod documented
404 4 my ($self, %opts) = @_;
405
406 4 ▶ my $name = delete $opts{name} or die "add_signature: name required";
Branch: 1 branch
BranchTrueFalseTotal
my $name = delete $opts{"name"} or die "add_signature: name required" 3 1 4
407 3 ▶ my $x = delete $opts{x} // 0;
Condition100%2/2
delete $opts{"x"} // 0
l!l
21
MC/DC100%1/1
delete $opts{"x"} // 0
delete $opts{"x"}
Truth table100%2/2
A
A= delete $opts{"x"}
Aresult
11
00
408 3 ▶ my $y = delete $opts{y} // 0;
Condition100%2/2
delete $opts{"y"} // 0
l!l
21
MC/DC100%1/1
delete $opts{"y"} // 0
delete $opts{"y"}
Truth table100%2/2
A
A= delete $opts{"y"}
Aresult
11
00
409 3 ▶ my $width = delete $opts{width} // 200;
Condition100%2/2
delete $opts{"width"} // 200
l!l
21
MC/DC100%1/1
delete $opts{"width"} // 200
delete $opts{"width"}
Truth table100%2/2
A
A= delete $opts{"width"}
Aresult
11
00
410 3 ▶ my $height = delete $opts{height} // 50;
Condition100%2/2
delete $opts{"height"} // 50
l!l
21
MC/DC100%1/1
delete $opts{"height"} // 50
delete $opts{"height"}
Truth table100%2/2
A
A= delete $opts{"height"}
Aresult
11
00
411
412 my $field = PDF::Make::FieldPtr::signature(
413 3 $self->{_doc}, $name, $x, $y, $width, $height
414 );
415
416 3 $self->_configure_field($field, %opts);
417
418 3 push @{$self->{_fields}}, $field;
419
420 3 return PDF::Make::Field->_wrap($field, $self);
421 }
422  
423 =head2 field_count
424  
425 my $count = $form->field_count();
426  
427 Return the number of top-level fields.
428  
429 =cut
430  
431 4 ▶sub field_count {
Subroutine field_count: called CC=1 SCAR=0.0
Pod documented
432 4 my ($self) = @_;
433 4 return $self->{_form}->field_count();
434 }
435  
436 =head2 field_at
437  
438 my $field = $form->field_at($index);
439  
440 Get field at the given index.
441  
442 =cut
443  
444 5 ▶sub field_at {
Subroutine field_at: called CC=2 SCAR=6.9
Pod documented
445 5 my ($self, $idx) = @_;
446 5 my $field = $self->{_form}->field_at($idx);
447 5 ▶ return unless $field;
Branch: 1 branch
BranchTrueFalseTotal
unless $field 2 3 5
448 3 return PDF::Make::Field->_wrap($field, $self);
449 }
450  
451 =head2 field_by_name
452  
453 my $field = $form->field_by_name('person.name.first');
454  
455 Find a field by its full name.
456  
457 =cut
458  
459 4 ▶sub field_by_name {
Subroutine field_by_name: called CC=2 SCAR=6.9
Pod documented
460 4 my ($self, $name) = @_;
461 4 my $field = $self->{_form}->field_by_name($name);
462 4 ▶ return unless $field;
Branch: 1 branch
BranchTrueFalseTotal
unless $field 2 2 4
463 2 return PDF::Make::Field->_wrap($field, $self);
464 }
465  
466 =head2 fields
467  
468 my @fields = $form->fields();
469  
470 Get all top-level fields.
471  
472 =cut
473  
474 2 ▶sub fields {
Subroutine fields: called CC=1 SCAR=0.0
Pod documented
475 2 my ($self) = @_;
476 2 return map { PDF::Make::Field->_wrap($_, $self) } $self->{_form}->fields();
477 }
478  
479 =head2 finalize
480  
481 $form->finalize();
482  
483 Finalize the form: create AcroForm dictionary, field dictionaries,
484 widget annotations, and appearance streams. Call this before rendering.
485  
486 =cut
487  
488 7 ▶sub finalize {
Subroutine finalize: called CC=1 SCAR=0.0
Pod documented
489 7 my ($self) = @_;
490 7 $self->{_form}->finalize();
491 7 return $self;
492 }
493  
494 =head2 flatten
495  
496 $form->flatten();
497  
498 Flatten all form fields: render values into page content and remove
499 interactive elements. After flattening, the PDF is no longer editable.
500  
501 =cut
502  
503 1 ▶sub flatten {
Subroutine flatten: called CC=1 SCAR=0.0
Pod documented
504 1 my ($self) = @_;
505 1 $self->{_form}->flatten();
506 1 return $self;
507 }
508  
509 =head2 export_fdf
510  
511 my $fdf_data = $form->export_fdf();
512  
513 Export form data in FDF format.
514  
515 =cut
516  
517 2 ▶sub export_fdf {
Subroutine export_fdf: called CC=1 SCAR=0.0
Pod documented
518 2 my ($self) = @_;
519 2 return $self->{_form}->export_fdf();
520 }
521  
522 =head2 export_xfdf
523  
524 my $xfdf_data = $form->export_xfdf();
525  
526 Export form data in XFDF (XML) format.
527  
528 =cut
529  
530 2 ▶sub export_xfdf {
Subroutine export_xfdf: called CC=1 SCAR=0.0
Pod documented
531 2 my ($self) = @_;
532 2 return $self->{_form}->export_xfdf();
533 }
534  
535 =head2 import_fdf
536  
537 $form->import_fdf($fdf_data);
538  
539 Import form data from FDF format.
540  
541 =cut
542  
543 1 ▶sub import_fdf {
Subroutine import_fdf: called CC=1 SCAR=0.0
Pod documented
544 1 my ($self, $data) = @_;
545 1 $self->{_form}->import_fdf($data);
546 1 return $self;
547 }
548  
549 =head2 import_xfdf
550  
551 $form->import_xfdf($xfdf_data);
552  
553 Import form data from XFDF format.
554  
555 =cut
556  
557 1 ▶sub import_xfdf {
Subroutine import_xfdf: called CC=1 SCAR=0.0
Pod documented
558 1 my ($self, $data) = @_;
559 1 $self->{_form}->import_xfdf($data);
560 1 return $self;
561 }
562  
563 =head2 set_need_appearances
564  
565 $form->set_need_appearances(1);
566  
567 Set the NeedAppearances flag. If true, the PDF viewer will generate
568 field appearances. If false (default), appearances are generated
569 during finalization.
570  
571 =cut
572  
573 4 ▶sub set_need_appearances {
Subroutine set_need_appearances: called CC=2 SCAR=6.9
Pod documented
574 4 my ($self, $need) = @_;
575 4 ▶ $self->{_form}->set_need_appearances($need ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$need ? : 2 2 4
576 4 return $self;
577 }
578  
579 # Internal: configure field with common options
580 56 ▶sub _configure_field {
Subroutine _configure_field: called CC=10 SCAR=23.0
581 56 my ($self, $field, %opts) = @_;
582
583 56 ▶ if (defined $opts{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"value"}) 8 48 56
584 8 $field->set_value($opts{value});
585 }
586 56 ▶ if (defined $opts{default_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"default_value"}) 1 55 56
587 1 $field->set_default_value($opts{default_value});
588 }
589 56 ▶ if (defined $opts{max_len}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"max_len"}) 2 54 56
590 2 $field->set_max_len($opts{max_len});
591 }
592 56 ▶ if (defined $opts{quadding}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"quadding"}) 1 55 56
593 1 $field->set_quadding($opts{quadding});
594 }
595 56 ▶ if (defined $opts{da}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"da"}) 1 55 56
596 1 $field->set_da($opts{da});
597 }
598
599 # Flags
600 56 ▶ if ($opts{multiline}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"multiline"}) 2 54 56
601 2 $field->multiline(1);
602 }
603 56 ▶ if ($opts{password}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"password"}) 1 55 56
604 1 $field->password(1);
605 }
606 56 ▶ if ($opts{readonly}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"readonly"}) 1 55 56
607 1 $field->readonly(1);
608 }
609 56 ▶ if ($opts{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"required"}) 1 55 56
610 1 $field->required(1);
611 }
612 }
613  
614 # Internal: get raw form pointer
615 0 ▶sub _form {
Subroutine _form: not called CC=1 SCAR=6.9
616 0 return $_[0]->{_form};
617 }
618  
619 3 1;
620  
621 __END__
« blib/lib/PDF/Make/Builder/Runs.pm ↑ Summary blib/lib/PDF/Make/Builder/Shape/Line.pm »