Bug 14383: C4: Fix some typos (mostly in comments and documentation)
[koha.git] / C4 / Creators / PDF.pm
1 package C4::Creators::PDF;
2
3 # Copyright 2009 Foundations Bible College.
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use strict;
21 use warnings;
22 use PDF::Reuse;
23 use PDF::Reuse::Barcode;
24 use File::Temp;
25 use List::Util qw/first/;
26
27 BEGIN {
28     use version; our $VERSION = qv('3.07.00.049');
29 }
30
31 sub _InitVars {
32     my $self = shift;
33     my $param = shift;
34     prInitVars($param);
35 }
36
37 sub new {
38     my $invocant = shift;
39     my $type = ref($invocant) || $invocant;
40     my %opts = @_;
41     my $self = {};
42     _InitVars() if ($opts{InitVars} == 0);
43     _InitVars($opts{InitVars}) if ($opts{InitVars} > 0);
44     delete($opts{InitVars});
45     prDocDir($opts{'DocDir'}) if $opts{'DocDir'};
46     delete($opts{'DocDir'});
47
48     my $fh = File::Temp->new( UNLINK => 0, SUFFIX => '.pdf' );
49     $opts{Name} = $self->{filename} = "$fh"; # filename
50     close $fh; # we need just filename
51
52     prFile(\%opts);
53     bless ($self, $type);
54     return $self;
55 }
56
57 sub End {
58     my $self = shift;
59
60     prEnd();
61
62     # slurp temporary filename and print it out for plack to pick up
63     local $/ = undef;
64     open(my $fh, '<', $self->{filename}) || die "$self->{filename}: $!";
65     print <$fh>;
66     close $fh;
67     unlink $self->{filename};
68 }
69
70 sub Add {
71     my $self = shift;
72     my $string = shift;
73     prAdd($string);
74 }
75
76 sub Bookmark {
77     my $self = shift;
78     my $reference = shift;
79     prBookmark($reference);
80 }
81
82 sub Compress {
83     my $self = shift;
84     my $directive = shift;
85     prCompress($directive);
86 }
87
88 sub Doc {
89     my $self = shift;
90     my %params = @_;
91     prDoc(%params);
92 }
93
94 sub DocForm {
95     my $self = shift;
96     my %params = @_;
97     return prDocForm(%params);
98 }
99
100 sub Extract {
101     my $self = shift;
102     my ($pdfFile, $pageNo, $oldInternalName) = @_;
103     return prExtract($pdfFile, $pageNo, $oldInternalName);
104 }
105
106 sub Field {
107     my $self = shift;
108     my ($fieldName, $value) = @_;
109     prField($fieldName, $value);
110 }
111
112 sub Font {
113     my $self = shift;
114     my $fontName = shift;
115
116     my $ttf = C4::Context->config('ttf');
117
118     if ( $ttf ) {
119         my $ttf_path = first { $_->{type} eq $fontName } @{ $ttf->{font} };
120         if ( -e $ttf_path->{content} ) {
121             return prTTFont($ttf_path->{content});
122         } else {
123             warn "ERROR in koha-conf.xml -- missing <font type=\"$fontName\">/path/to/font.ttf</font>";
124         }
125     }
126     return prFont($fontName);
127 }
128
129 sub FontSize {
130     my $self = shift;
131     my $size = shift;
132     return prFontSize($size);
133 }
134
135 sub Form {
136     my $self = shift;
137     my %params = @_;
138     return prForm(%params);
139 }
140
141 sub GetLogBuffer {
142     my $self = shift;
143     return prGetLogBuffer();
144 }
145
146 sub GraphState {
147     my $self = shift;
148     my $string = shift;
149     prGraphState($string);
150 }
151
152 sub Image {
153     my $self = shift;
154     my %params = @_;
155     return prImage(%params);
156 }
157
158 sub Init {
159     my $self = shift;
160     my ($string, $duplicateCode) = @_;
161     prInit($string, $duplicateCode);
162 }
163
164 sub AltJpeg {
165     my $self = shift;
166     my ($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat) = @_;
167     return prAltJpeg($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat);
168 }
169
170 sub Jpeg {
171     my $self = shift;
172     my ($imageData, $width, $height, $imageFormat) = @_;
173     return prJpeg($imageData, $width, $height, $imageFormat);
174 }
175
176 sub Js {
177     my $self = shift;
178     my $string_or_fileName = shift;
179     prJs($string_or_fileName);
180 }
181
182 sub Link {
183     my $self = shift;
184     my %params = @_;
185     prLink(%params);
186 }
187
188 sub Log {
189     my $self = shift;
190     my $string = shift;
191     prLog($string);
192 }
193
194 sub LogDir {
195     my $self = shift;
196     my $directory = shift;
197     prLogDir($directory);
198 }
199
200 sub Mbox {
201     my $self = shift;
202     my ($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY) = @_;
203     prMbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
204 }
205
206 sub Page {
207     my $self = shift;
208     my $noLog = shift;
209     prPage($noLog);
210 }
211
212 sub SinglePage {
213     my $self = shift;
214     my ($file, $pageNumber) = @_;
215     return prSinglePage($file, $pageNumber);
216 }
217
218 sub StrWidth {
219     my $self = shift;
220     my ($string, $font, $fontSize) = @_;
221
222     # replace font code with path to TTF font file if need be
223     my $ttf = C4::Context->config('ttf');
224     if ( $ttf ) {
225         my $ttf_path = first { $_->{type} eq $font } @{ $ttf->{font} };
226         if ( -e $ttf_path->{content} ) {
227             $font = $ttf_path->{content};
228         } else {
229             warn "ERROR in koha-conf.xml -- missing <font type=\"$font\">/path/to/font.ttf</font>";
230         }
231     }
232
233     return prStrWidth($string, $font, $fontSize);
234 }
235
236 sub Text {
237     my $self = shift;
238     my ($x, $y, $string, $align, $rotation) = @_;
239     return prText($x, $y, $string, $align, $rotation);
240 }
241
242 sub TTFont {
243     my $self = shift;
244     my $path = shift;
245     return prTTFont($path);
246 }
247
248 sub Code128 {
249     my $self = shift;
250     my %opts = @_;
251     PDF::Reuse::Barcode::Code128(%opts);
252 }
253
254 sub Code39 {
255     my $self = shift;
256     my %opts = @_;
257     PDF::Reuse::Barcode::Code39(%opts);
258 }
259
260 sub COOP2of5 {
261     my $self = shift;
262     my %opts = @_;
263     PDF::Reuse::Barcode::COOP2of5(%opts);
264 }
265
266 sub EAN13 {
267     my $self = shift;
268     my %opts = @_;
269     PDF::Reuse::Barcode::EAN13(%opts);
270 }
271
272 sub EAN8 {
273     my $self = shift;
274     my %opts = @_;
275     PDF::Reuse::Barcode::EAN8(%opts);
276 }
277
278 sub IATA2of5 {
279     my $self = shift;
280     my %opts = @_;
281     PDF::Reuse::Barcode::IATA2of5(%opts);
282 }
283
284 sub Industrial2of5 {
285     my $self = shift;
286     my %opts = @_;
287     PDF::Reuse::Barcode::Industrial2of5(%opts);
288 }
289
290 sub ITF {
291     my $self = shift;
292     my %opts = @_;
293     PDF::Reuse::Barcode::ITF(%opts);
294 }
295
296 sub Matrix2of5 {
297     my $self = shift;
298     my %opts = @_;
299     PDF::Reuse::Barcode::Matrix2of5(%opts);
300 }
301
302 sub NW7 {
303     my $self = shift;
304     my %opts = @_;
305     PDF::Reuse::Barcode::NW7(%opts);
306 }
307
308 sub UPCA {
309     my $self = shift;
310     my %opts = @_;
311     PDF::Reuse::Barcode::UPCA(%opts);
312 }
313
314 sub UPCE {
315     my $self = shift;
316     my %opts = @_;
317     PDF::Reuse::Barcode::UPCE(%opts);
318 }
319
320 1;
321 __END__
322
323
324 =head1 NAME
325
326 C4::Creators::PDF -   A class wrapper for PDF::Reuse and PDF::Reuse::Barcode to allow usage as a pseudo-object. For usage see
327                     PDF::Reuse documentation and C4::Creators::PDF code.
328
329 =cut
330
331 =head1 AUTHOR
332
333 Chris Nighswonger <cnighswonger AT foundations DOT edu>
334
335 =cut