Bug 27921: Log correct timestamp for HOLD MODIFY when set waiting
[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
28 sub _InitVars {
29     my $self = shift;
30     my $param = shift;
31     prInitVars($param);
32 }
33
34 sub new {
35     my $invocant = shift;
36     my $type = ref($invocant) || $invocant;
37     my %opts = @_;
38     my $self = {};
39     _InitVars() if ($opts{InitVars} == 0);
40     _InitVars($opts{InitVars}) if ($opts{InitVars} > 0);
41     delete($opts{InitVars});
42     prDocDir($opts{'DocDir'}) if $opts{'DocDir'};
43     delete($opts{'DocDir'});
44
45     my $fh = File::Temp->new( UNLINK => 0, SUFFIX => '.pdf' );
46     $opts{Name} = $self->{filename} = "$fh"; # filename
47     close $fh; # we need just filename
48
49     prFile(\%opts);
50     bless ($self, $type);
51     return $self;
52 }
53
54 sub End {
55     my $self = shift;
56
57     prEnd();
58
59     # slurp temporary filename and print it out for plack to pick up
60     local $/ = undef;
61     open(my $fh, '<', $self->{filename}) || die "$self->{filename}: $!";
62     print <$fh>;
63     close $fh;
64     unlink $self->{filename};
65 }
66
67 sub Add {
68     my $self = shift;
69     my $string = shift;
70     prAdd($string);
71 }
72
73 sub Bookmark {
74     my $self = shift;
75     my $reference = shift;
76     prBookmark($reference);
77 }
78
79 sub Compress {
80     my $self = shift;
81     my $directive = shift;
82     prCompress($directive);
83 }
84
85 sub Doc {
86     my $self = shift;
87     my %params = @_;
88     prDoc(%params);
89 }
90
91 sub DocForm {
92     my $self = shift;
93     my %params = @_;
94     return prDocForm(%params);
95 }
96
97 sub Extract {
98     my $self = shift;
99     my ($pdfFile, $pageNo, $oldInternalName) = @_;
100     return prExtract($pdfFile, $pageNo, $oldInternalName);
101 }
102
103 sub Field {
104     my $self = shift;
105     my ($fieldName, $value) = @_;
106     prField($fieldName, $value);
107 }
108
109 sub Font {
110     my $self = shift;
111     my $fontName = shift;
112
113     my $ttf = C4::Context->config('ttf');
114
115     if ( $ttf ) {
116         my $ttf_path = first { $_->{type} eq $fontName } @{ $ttf->{font} };
117         if ( -e $ttf_path->{content} ) {
118             return prTTFont($ttf_path->{content});
119         } else {
120             warn "ERROR in koha-conf.xml -- missing <font type=\"$fontName\">/path/to/font.ttf</font>";
121         }
122     }
123     return prFont($fontName);
124 }
125
126 sub FontSize {
127     my $self = shift;
128     my $size = shift;
129     return prFontSize($size);
130 }
131
132 sub Form {
133     my $self = shift;
134     my %params = @_;
135     return prForm(%params);
136 }
137
138 sub GetLogBuffer {
139     my $self = shift;
140     return prGetLogBuffer();
141 }
142
143 sub GraphState {
144     my $self = shift;
145     my $string = shift;
146     prGraphState($string);
147 }
148
149 sub Image {
150     my $self = shift;
151     my %params = @_;
152     return prImage(%params);
153 }
154
155 sub Init {
156     my $self = shift;
157     my ($string, $duplicateCode) = @_;
158     prInit($string, $duplicateCode);
159 }
160
161 sub AltJpeg {
162     my $self = shift;
163     my ($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat) = @_;
164     return prAltJpeg($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat);
165 }
166
167 sub Jpeg {
168     my $self = shift;
169     my ($imageData, $width, $height, $imageFormat) = @_;
170     return prJpeg($imageData, $width, $height, $imageFormat);
171 }
172
173 sub Js {
174     my $self = shift;
175     my $string_or_fileName = shift;
176     prJs($string_or_fileName);
177 }
178
179 sub Link {
180     my $self = shift;
181     my %params = @_;
182     prLink(%params);
183 }
184
185 sub Log {
186     my $self = shift;
187     my $string = shift;
188     prLog($string);
189 }
190
191 sub LogDir {
192     my $self = shift;
193     my $directory = shift;
194     prLogDir($directory);
195 }
196
197 sub Mbox {
198     my $self = shift;
199     my ($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY) = @_;
200     prMbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
201 }
202
203 sub Page {
204     my $self = shift;
205     my $noLog = shift;
206     prPage($noLog);
207 }
208
209 sub SinglePage {
210     my $self = shift;
211     my ($file, $pageNumber) = @_;
212     return prSinglePage($file, $pageNumber);
213 }
214
215 sub StrWidth {
216     my $self = shift;
217     my ($string, $font, $fontSize) = @_;
218
219     # replace font code with correct internal font
220     $font = C4::Creators::PDF->Font($font);
221
222     return prStrWidth($string, $font, $fontSize);
223 }
224
225 sub Text {
226     my $self = shift;
227     my ($x, $y, $string, $align, $rotation) = @_;
228     return prText($x, $y, $string, $align, $rotation);
229 }
230
231 sub TTFont {
232     my $self = shift;
233     my $path = shift;
234     return prTTFont($path);
235 }
236
237 sub Code128 {
238     my $self = shift;
239     my %opts = @_;
240     PDF::Reuse::Barcode::Code128(%opts);
241 }
242
243 sub Code39 {
244     my $self = shift;
245     my %opts = @_;
246     PDF::Reuse::Barcode::Code39(%opts);
247 }
248
249 sub COOP2of5 {
250     my $self = shift;
251     my %opts = @_;
252     PDF::Reuse::Barcode::COOP2of5(%opts);
253 }
254
255 sub EAN13 {
256     my $self = shift;
257     my %opts = @_;
258     PDF::Reuse::Barcode::EAN13(%opts);
259 }
260
261 sub EAN8 {
262     my $self = shift;
263     my %opts = @_;
264     PDF::Reuse::Barcode::EAN8(%opts);
265 }
266
267 sub IATA2of5 {
268     my $self = shift;
269     my %opts = @_;
270     PDF::Reuse::Barcode::IATA2of5(%opts);
271 }
272
273 sub Industrial2of5 {
274     my $self = shift;
275     my %opts = @_;
276     PDF::Reuse::Barcode::Industrial2of5(%opts);
277 }
278
279 sub ITF {
280     my $self = shift;
281     my %opts = @_;
282     PDF::Reuse::Barcode::ITF(%opts);
283 }
284
285 sub Matrix2of5 {
286     my $self = shift;
287     my %opts = @_;
288     PDF::Reuse::Barcode::Matrix2of5(%opts);
289 }
290
291 sub NW7 {
292     my $self = shift;
293     my %opts = @_;
294     PDF::Reuse::Barcode::NW7(%opts);
295 }
296
297 sub UPCA {
298     my $self = shift;
299     my %opts = @_;
300     PDF::Reuse::Barcode::UPCA(%opts);
301 }
302
303 sub UPCE {
304     my $self = shift;
305     my %opts = @_;
306     PDF::Reuse::Barcode::UPCE(%opts);
307 }
308
309 1;
310 __END__
311
312
313 =head1 NAME
314
315 C4::Creators::PDF -   A class wrapper for PDF::Reuse and PDF::Reuse::Barcode to allow usage as a pseudo-object. For usage see
316                     PDF::Reuse documentation and C4::Creators::PDF code.
317
318 =cut
319
320 =head1 AUTHOR
321
322 Chris Nighswonger <cnighswonger AT foundations DOT edu>
323
324 =cut