Bug 16419: follow-up of bug 11371 - Fix t/db_dependent/Acquisition.t
[koha.git] / C4 / Creators / PDF.pm
blob9796feb832884a8234ade3d1d7a0681bc1f25437
1 package C4::Creators::PDF;
3 # Copyright 2009 Foundations Bible College.
5 # This file is part of Koha.
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.
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.
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>.
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/;
28 sub _InitVars {
29 my $self = shift;
30 my $param = shift;
31 prInitVars($param);
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'});
45 my $fh = File::Temp->new( UNLINK => 0, SUFFIX => '.pdf' );
46 $opts{Name} = $self->{filename} = "$fh"; # filename
47 close $fh; # we need just filename
49 prFile(\%opts);
50 bless ($self, $type);
51 return $self;
54 sub End {
55 my $self = shift;
57 prEnd();
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};
67 sub Add {
68 my $self = shift;
69 my $string = shift;
70 prAdd($string);
73 sub Bookmark {
74 my $self = shift;
75 my $reference = shift;
76 prBookmark($reference);
79 sub Compress {
80 my $self = shift;
81 my $directive = shift;
82 prCompress($directive);
85 sub Doc {
86 my $self = shift;
87 my %params = @_;
88 prDoc(%params);
91 sub DocForm {
92 my $self = shift;
93 my %params = @_;
94 return prDocForm(%params);
97 sub Extract {
98 my $self = shift;
99 my ($pdfFile, $pageNo, $oldInternalName) = @_;
100 return prExtract($pdfFile, $pageNo, $oldInternalName);
103 sub Field {
104 my $self = shift;
105 my ($fieldName, $value) = @_;
106 prField($fieldName, $value);
109 sub Font {
110 my $self = shift;
111 my $fontName = shift;
113 my $ttf = C4::Context->config('ttf');
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>";
123 return prFont($fontName);
126 sub FontSize {
127 my $self = shift;
128 my $size = shift;
129 return prFontSize($size);
132 sub Form {
133 my $self = shift;
134 my %params = @_;
135 return prForm(%params);
138 sub GetLogBuffer {
139 my $self = shift;
140 return prGetLogBuffer();
143 sub GraphState {
144 my $self = shift;
145 my $string = shift;
146 prGraphState($string);
149 sub Image {
150 my $self = shift;
151 my %params = @_;
152 return prImage(%params);
155 sub Init {
156 my $self = shift;
157 my ($string, $duplicateCode) = @_;
158 prInit($string, $duplicateCode);
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);
167 sub Jpeg {
168 my $self = shift;
169 my ($imageData, $width, $height, $imageFormat) = @_;
170 return prJpeg($imageData, $width, $height, $imageFormat);
173 sub Js {
174 my $self = shift;
175 my $string_or_fileName = shift;
176 prJs($string_or_fileName);
179 sub Link {
180 my $self = shift;
181 my %params = @_;
182 prLink(%params);
185 sub Log {
186 my $self = shift;
187 my $string = shift;
188 prLog($string);
191 sub LogDir {
192 my $self = shift;
193 my $directory = shift;
194 prLogDir($directory);
197 sub Mbox {
198 my $self = shift;
199 my ($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY) = @_;
200 prMbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
203 sub Page {
204 my $self = shift;
205 my $noLog = shift;
206 prPage($noLog);
209 sub SinglePage {
210 my $self = shift;
211 my ($file, $pageNumber) = @_;
212 return prSinglePage($file, $pageNumber);
215 sub StrWidth {
216 my $self = shift;
217 my ($string, $font, $fontSize) = @_;
219 # replace font code with correct internal font
220 $font = C4::Creators::PDF->Font($font);
222 return prStrWidth($string, $font, $fontSize);
225 sub Text {
226 my $self = shift;
227 my ($x, $y, $string, $align, $rotation) = @_;
228 return prText($x, $y, $string, $align, $rotation);
231 sub TTFont {
232 my $self = shift;
233 my $path = shift;
234 return prTTFont($path);
237 sub Code128 {
238 my $self = shift;
239 my %opts = @_;
240 PDF::Reuse::Barcode::Code128(%opts);
243 sub Code39 {
244 my $self = shift;
245 my %opts = @_;
246 PDF::Reuse::Barcode::Code39(%opts);
249 sub COOP2of5 {
250 my $self = shift;
251 my %opts = @_;
252 PDF::Reuse::Barcode::COOP2of5(%opts);
255 sub EAN13 {
256 my $self = shift;
257 my %opts = @_;
258 PDF::Reuse::Barcode::EAN13(%opts);
261 sub EAN8 {
262 my $self = shift;
263 my %opts = @_;
264 PDF::Reuse::Barcode::EAN8(%opts);
267 sub IATA2of5 {
268 my $self = shift;
269 my %opts = @_;
270 PDF::Reuse::Barcode::IATA2of5(%opts);
273 sub Industrial2of5 {
274 my $self = shift;
275 my %opts = @_;
276 PDF::Reuse::Barcode::Industrial2of5(%opts);
279 sub ITF {
280 my $self = shift;
281 my %opts = @_;
282 PDF::Reuse::Barcode::ITF(%opts);
285 sub Matrix2of5 {
286 my $self = shift;
287 my %opts = @_;
288 PDF::Reuse::Barcode::Matrix2of5(%opts);
291 sub NW7 {
292 my $self = shift;
293 my %opts = @_;
294 PDF::Reuse::Barcode::NW7(%opts);
297 sub UPCA {
298 my $self = shift;
299 my %opts = @_;
300 PDF::Reuse::Barcode::UPCA(%opts);
303 sub UPCE {
304 my $self = shift;
305 my %opts = @_;
306 PDF::Reuse::Barcode::UPCE(%opts);
310 __END__
313 =head1 NAME
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.
318 =cut
320 =head1 AUTHOR
322 Chris Nighswonger <cnighswonger AT foundations DOT edu>
324 =cut