line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::Report::Table; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
PDF::Report::Table - Adds table support to PDF::Report |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use PDF::Report; |
10
|
|
|
|
|
|
|
use PDF::Report::Table; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $pdf = new PDF::Report( |
13
|
|
|
|
|
|
|
'PageSize' => 'letter', |
14
|
|
|
|
|
|
|
'PageOrientation' => 'Portrait', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $table_writer = PDF::Report::Table->new($pdf); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $some_data =[ |
20
|
|
|
|
|
|
|
["test1", "test2", "test3"], |
21
|
|
|
|
|
|
|
["test4", "test5", "test6"], |
22
|
|
|
|
|
|
|
["test7", "test8", "test9"], |
23
|
|
|
|
|
|
|
]; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$table_writer->addTable($some_data); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Add tables to PDF::Report. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
27161
|
use strict; |
|
1
|
|
|
|
|
118
|
|
|
1
|
|
|
|
|
38
|
|
34
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
1430
|
use PDF::Report; |
|
1
|
|
|
|
|
291513
|
|
|
1
|
|
|
|
|
37
|
|
37
|
1
|
|
|
1
|
|
1079
|
use PDF::Table; |
|
1
|
|
|
|
|
4643
|
|
|
1
|
|
|
|
|
280
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item $new($pdf); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $pdf = new PDF::Report( |
45
|
|
|
|
|
|
|
'PageSize' => 'letter', |
46
|
|
|
|
|
|
|
'PageOrientation' => 'Portrait', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $table_writer = PDF::Report::Table->new($pdf); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
55
|
0
|
|
|
|
|
|
my $report = shift; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $self = {}; |
58
|
0
|
|
|
|
|
|
bless $self, $class; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->{report} = $report; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item $table_writer->addTable(@data); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$table_writer->addTable( |
68
|
|
|
|
|
|
|
$some_data, # 2d array |
69
|
|
|
|
|
|
|
$width, # default is none |
70
|
|
|
|
|
|
|
$padding, # default is 5 |
71
|
|
|
|
|
|
|
$bgcolor_odd, # default is '#FFFFFF' |
72
|
|
|
|
|
|
|
$bgcolor_even, # default is '#FFFFCC' |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub addTable { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift @_; |
79
|
0
|
|
|
|
|
|
my $data = shift @_; |
80
|
0
|
|
0
|
|
|
|
my $width = shift @_ || ''; |
81
|
0
|
|
0
|
|
|
|
my $padding = shift @_ || 5; |
82
|
0
|
|
0
|
|
|
|
my $bgcolor_odd = shift @_ || "#FFFFFF"; |
83
|
0
|
|
0
|
|
|
|
my $bgcolor_even = shift @_ || "#FFFFCC"; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $pdftable = new PDF::Table; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Figure out if it'll fit on the current page (this may need tweaking) |
88
|
0
|
0
|
|
|
|
|
if (($self->{report}->{vPos} - (length($data) * ((2 * $padding) + 12))) < 0) { |
89
|
0
|
|
|
|
|
|
$self->{report}->{vPos} = $self->{report}->{PageHeight} - $self->{report}->{Ymargin}; |
90
|
0
|
|
|
|
|
|
$self->{report}->newpage(); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Add to page |
94
|
0
|
|
|
|
|
|
my ($end_page, $pages_spanned, $table_bot_y) = $pdftable->table( |
95
|
|
|
|
|
|
|
# required params |
96
|
|
|
|
|
|
|
$self->{report}->{pdf}, |
97
|
|
|
|
|
|
|
$self->{report}->{page}, |
98
|
|
|
|
|
|
|
$data, |
99
|
|
|
|
|
|
|
-x => $self->{report}->{hPos}, |
100
|
|
|
|
|
|
|
-start_y => $self->{report}->{vPos}, |
101
|
|
|
|
|
|
|
-start_h => $self->{report}->{PageHeight}, |
102
|
|
|
|
|
|
|
-w => $width, |
103
|
|
|
|
|
|
|
-padding => $padding, |
104
|
|
|
|
|
|
|
-background_color_odd => $bgcolor_odd, |
105
|
|
|
|
|
|
|
-background_color_even => $bgcolor_even, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Set baseline for next position |
109
|
0
|
|
|
|
|
|
$self->{report}->{vPos} = $table_bot_y - 20; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
__END__ |