line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::Boxer; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$PDF::Boxer::VERSION = '0.001'; # TRIAL |
4
|
|
|
|
|
|
|
} |
5
|
3
|
|
|
3
|
|
2681
|
use Moose; |
|
3
|
|
|
|
|
1150179
|
|
|
3
|
|
|
|
|
26
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Create PDFs from a simple box markup language. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
21921
|
use namespace::autoclean; |
|
3
|
|
|
|
|
18777
|
|
|
3
|
|
|
|
|
13
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
1083
|
use PDF::Boxer::Doc; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
144
|
|
13
|
3
|
|
|
3
|
|
1591
|
use PDF::Boxer::Content::Box; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
116
|
|
14
|
3
|
|
|
3
|
|
1543
|
use PDF::Boxer::Content::Text; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
115
|
|
15
|
3
|
|
|
3
|
|
1471
|
use PDF::Boxer::Content::Image; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
125
|
|
16
|
3
|
|
|
3
|
|
1456
|
use PDF::Boxer::Content::Row; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
118
|
|
17
|
3
|
|
|
3
|
|
1468
|
use PDF::Boxer::Content::Column; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
115
|
|
18
|
3
|
|
|
3
|
|
1364
|
use PDF::Boxer::Content::Grid; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
115
|
|
19
|
3
|
|
|
3
|
|
22
|
use Try::Tiny; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
198
|
|
20
|
3
|
|
|
3
|
|
15
|
use Scalar::Util qw/weaken/; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
116
|
|
21
|
3
|
|
|
3
|
|
14
|
use Moose::Util::TypeConstraints; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
32
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
coerce 'PDF::Boxer::Doc' |
24
|
|
|
|
|
|
|
=> from 'HashRef' |
25
|
|
|
|
|
|
|
=> via { PDF::Boxer::Doc->new($_) }; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'debug' => ( isa => 'Bool', is => 'ro', default => 0 ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'doc' => ( isa => 'PDF::Boxer::Doc', is => 'ro', coerce => 1 ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has 'max_width' => ( isa => 'Int', is => 'rw', default => 595 ); |
32
|
|
|
|
|
|
|
has 'max_height' => ( isa => 'Int', is => 'rw', default => 842 ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'box_register' => ( isa => 'HashRef', is => 'ro', default => sub{{}} ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub register_box{ |
37
|
0
|
|
|
0
|
0
|
|
my ($self, $box) = @_; |
38
|
0
|
0
|
|
|
|
|
return unless $box->name; |
39
|
0
|
|
|
|
|
|
weaken($box); |
40
|
0
|
|
|
|
|
|
$self->box_register->{$box->name} = $box; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub box_lookup{ |
44
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
45
|
0
|
|
|
|
|
|
return $self->box_register->{$name}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub add_to_pdf{ |
49
|
0
|
|
|
0
|
1
|
|
my ($self, $spec) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $weak_me = $self; |
52
|
0
|
|
|
|
|
|
weaken($weak_me); |
53
|
0
|
|
|
|
|
|
$spec->{boxer} = $weak_me; |
54
|
0
|
|
|
|
|
|
$spec->{debug} = $self->debug; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $class = 'PDF::Boxer::Content::'.$spec->{type}; |
57
|
0
|
|
|
|
|
|
my $node = $class->new($spec); |
58
|
0
|
|
|
|
|
|
$self->register_box($node); |
59
|
0
|
|
|
|
|
|
$node->initialize; |
60
|
|
|
|
|
|
|
# $node->ruler_h; |
61
|
0
|
|
|
|
|
|
$node->render; |
62
|
0
|
|
|
|
|
|
return $node; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub finish{ |
66
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
67
|
0
|
|
|
|
|
|
$self->doc->pdf->save; |
68
|
0
|
|
|
|
|
|
$self->doc->pdf->end; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |
76
|
|
|
|
|
|
|
=pod |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
PDF::Boxer - Create PDFs from a simple box markup language. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
version 0.001 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$pdfml = <<'__EOP__'; |
89
|
|
|
|
|
|
|
<column max_width="595" max_height="842"> |
90
|
|
|
|
|
|
|
<column border_color="blue" border="2"> |
91
|
|
|
|
|
|
|
<row> |
92
|
|
|
|
|
|
|
<image src="t/lecstor.gif" align="center" valign="center" padding="10" scale="60" /> |
93
|
|
|
|
|
|
|
<column grow="1" padding="10 10 10 0"> |
94
|
|
|
|
|
|
|
<text padding="3" align="right" size="20"> |
95
|
|
|
|
|
|
|
Lecstor Pty Ltd |
96
|
|
|
|
|
|
|
</text> |
97
|
|
|
|
|
|
|
<text padding="3" align="right" size="14"> |
98
|
|
|
|
|
|
|
123 Example St, Somewhere, Qld 4879 |
99
|
|
|
|
|
|
|
</text> |
100
|
|
|
|
|
|
|
</column> |
101
|
|
|
|
|
|
|
</row> |
102
|
|
|
|
|
|
|
<row padding="15 0"> |
103
|
|
|
|
|
|
|
<text padding="20" size="14"> |
104
|
|
|
|
|
|
|
Mr G Client |
105
|
|
|
|
|
|
|
Shop 2 Some Centre, Retail Rd |
106
|
|
|
|
|
|
|
Somewhere, NSW 2000 |
107
|
|
|
|
|
|
|
</text> |
108
|
|
|
|
|
|
|
<column padding="20" border_color="red" grow="1"> |
109
|
|
|
|
|
|
|
<text size="16" align="right" font="Helvetica-Bold"> |
110
|
|
|
|
|
|
|
Tax Invoice No. 123 |
111
|
|
|
|
|
|
|
</text> |
112
|
|
|
|
|
|
|
<text size="14" align="right"> |
113
|
|
|
|
|
|
|
Issued 01/01/2011 |
114
|
|
|
|
|
|
|
</text> |
115
|
|
|
|
|
|
|
<text size="14" align="right" font="Helvetica-Bold"> |
116
|
|
|
|
|
|
|
Due 14/01/2011 |
117
|
|
|
|
|
|
|
</text> |
118
|
|
|
|
|
|
|
</column> |
119
|
|
|
|
|
|
|
</row> |
120
|
|
|
|
|
|
|
</column> |
121
|
|
|
|
|
|
|
<grid padding="10"> |
122
|
|
|
|
|
|
|
<row font="Helvetica-Bold" padding="0"> |
123
|
|
|
|
|
|
|
<text align="center" padding="0 10">Name</text> |
124
|
|
|
|
|
|
|
<text grow="1" align="center" padding="0 10">Description</text> |
125
|
|
|
|
|
|
|
<text padding="0 10" align="center">GST Amount</text> |
126
|
|
|
|
|
|
|
<text padding="0 10" align="center">Payable Amount</text> |
127
|
|
|
|
|
|
|
</row> |
128
|
|
|
|
|
|
|
<row margin="10 0 0 0"> |
129
|
|
|
|
|
|
|
<text padding="0 5">Web Services</text> |
130
|
|
|
|
|
|
|
<text name="ItemText2" grow="1" padding="0 5"> |
131
|
|
|
|
|
|
|
a long description which needs to be wrapped to fit in the box |
132
|
|
|
|
|
|
|
</text> |
133
|
|
|
|
|
|
|
<text padding="0 5" align="right">$9999.99</text> |
134
|
|
|
|
|
|
|
<text padding="0 5" align="right">$99999.99</text> |
135
|
|
|
|
|
|
|
</row> |
136
|
|
|
|
|
|
|
</grid> |
137
|
|
|
|
|
|
|
</column> |
138
|
|
|
|
|
|
|
__EOP__ |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$parser = PDF::Boxer::SpecParser->new; |
141
|
|
|
|
|
|
|
$spec = $parser->parse($pdfml); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$boxer = PDF::Boxer->new( doc => { file => 'test_invoice.pdf' } ); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$boxer->add_to_pdf($spec); |
146
|
|
|
|
|
|
|
$boxer->finish; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 DESCRIPTION |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Use my version of a "box model" layout to create PDFs. |
151
|
|
|
|
|
|
|
Use PDF::Boxer::SpecParser to parse a template written in the not so patented PDFML. |
152
|
|
|
|
|
|
|
Suggestion: Use L<Template> to dynamically create your PDFML template. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 METHODS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 add_to_pdf |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$boxer->add_to_pdf($spec); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 NAME |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
PDF::Boxer |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AUTHOR |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Jason Galea <lecstor@cpan.org> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Jason Galea. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
173
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|