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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use PDF
::Reuse
::Barcode
;
25 use List
::Util qw
/first/;
28 use version
; our $VERSION = qv
('3.07.00.049');
39 my $type = ref($invocant) || $invocant;
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'});
48 my $fh = File
::Temp
->new( UNLINK
=> 0, SUFFIX
=> '.pdf' );
49 $opts{Name
} = $self->{filename
} = "$fh"; # filename
50 close $fh; # we need just filename
62 # slurp temporary filename and print it out for plack to pick up
64 open(my $fh, '<', $self->{filename
}) || die "$self->{filename}: $!";
67 unlink $self->{filename
};
78 my $reference = shift;
79 prBookmark
($reference);
84 my $directive = shift;
85 prCompress
($directive);
97 return prDocForm
(%params);
102 my ($pdfFile, $pageNo, $oldInternalName) = @_;
103 return prExtract
($pdfFile, $pageNo, $oldInternalName);
108 my ($fieldName, $value) = @_;
109 prField
($fieldName, $value);
114 my $fontName = shift;
116 my $ttf = C4
::Context
->config('ttf');
119 my $ttf_path = first
{ $_->{type
} eq $fontName } @
{ $ttf->{font
} };
120 if ( -e
$ttf_path->{content
} ) {
121 return prTTFont
($ttf_path->{content
});
123 warn "ERROR in koha-conf.xml -- missing <font type=\"$fontName\">/path/to/font.ttf</font>";
126 return prFont
($fontName);
132 return prFontSize
($size);
138 return prForm
(%params);
143 return prGetLogBuffer
();
149 prGraphState
($string);
155 return prImage
(%params);
160 my ($string, $duplicateCode) = @_;
161 prInit
($string, $duplicateCode);
166 my ($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat) = @_;
167 return prAltJpeg
($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat);
172 my ($imageData, $width, $height, $imageFormat) = @_;
173 return prJpegBlob
($imageData, $width, $height, $imageFormat);
176 # FIXME: This magick foo is an absolute hack until the maintainer of PDF::Reuse releases the next version which will include these features
179 { my ($iData, $iWidth, $iHeight, $iFormat,$aiData, $aiWidth, $aiHeight, $aiFormat) = @_;
180 my ($namnet, $utrad);
181 if (! $PDF::Reuse
::pos) # If no output is active, it is no use to continue
184 prJpegBlob
($aiData, $aiWidth, $aiHeight, $aiFormat);
185 my $altObjNr = $PDF::Reuse
::objNr
;
186 $PDF::Reuse
::imageNr
++;
187 $namnet = 'Ig' . $PDF::Reuse
::imageNr
;
188 $PDF::Reuse
::objNr
++;
189 $PDF::Reuse
::objekt
[$PDF::Reuse
::objNr
] = $PDF::Reuse
::pos;
190 $utrad = "$PDF::Reuse::objNr 0 obj\n" .
191 "[ << /Image $altObjNr 0 R\n" .
192 "/DefaultForPrinting true\n" .
196 $PDF::Reuse
::pos += syswrite *PDF
::Reuse
::UTFIL
, $utrad;
197 if ($PDF::Reuse
::runfil
)
198 { $PDF::Reuse
::log .= "Jpeg~AltImage\n";
200 $PDF::Reuse
::objRef
{$namnet} = $PDF::Reuse
::objNr
;
201 $namnet = prJpegBlob
($iData, $iWidth, $iHeight, $iFormat, $PDF::Reuse
::objNr
);
202 if (! $PDF::Reuse
::pos)
203 { errLog
("No output file, you have to call prFile first");
209 { my ($iData, $iWidth, $iHeight, $iFormat, $altArrayObjNr) = @_;
210 my ($iLangd, $namnet, $utrad);
211 if (! $PDF::Reuse
::pos) # If no output is active, it is no use to continue
214 my $checkidOld = $PDF::Reuse
::checkId
;
216 { my ($iFile, $checkId) = findGet
($iData, $checkidOld);
218 { $iLangd = (stat($iFile))[7];
219 $PDF::Reuse
::imageNr
++;
220 $namnet = 'Ig' . $PDF::Reuse
::imageNr
;
221 $PDF::Reuse
::objNr
++;
222 $PDF::Reuse
::objekt
[$PDF::Reuse
::objNr
] = $PDF::Reuse
::pos;
223 open (my $fh, '<', "$iFile") || errLog
("Couldn't open $iFile, $!, aborts");
226 sysread $fh, $iStream, $iLangd;
227 $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
228 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
229 ($altArrayObjNr ?
"/Alternates $altArrayObjNr 0 R " : "") .
230 "/Filter/DCTDecode/ColorSpace/DeviceRGB"
231 . "/Length $iLangd >>stream\n$iStream\nendstream\nendobj\n";
233 $PDF::Reuse
::pos += syswrite $PDF::Reuse
::UTFIL
, $utrad;
234 if ($PDF::Reuse
::runfil
)
235 { $PDF::Reuse
::log .= "Cid~$PDF::Reuse::checkId\n";
236 $PDF::Reuse
::log .= "Jpeg~$iFile~$iWidth~$iHeight\n";
238 $PDF::Reuse
::objRef
{$namnet} = $PDF::Reuse
::objNr
;
242 elsif ($iFormat == 1)
243 { my $iBlob = $iData;
244 $iLangd = length($iBlob);
245 $PDF::Reuse
::imageNr
++;
246 $namnet = 'Ig' . $PDF::Reuse
::imageNr
;
247 $PDF::Reuse
::objNr
++;
248 $PDF::Reuse
::objekt
[$PDF::Reuse
::objNr
] = $PDF::Reuse
::pos;
249 $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
250 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
251 ($altArrayObjNr ?
"/Alternates $altArrayObjNr 0 R " : "") .
252 "/Filter/DCTDecode/ColorSpace/DeviceRGB"
253 . "/Length $iLangd >>stream\n$iBlob\nendstream\nendobj\n";
254 $PDF::Reuse
::pos += syswrite *PDF
::Reuse
::UTFIL
, $utrad;
255 if ($PDF::Reuse
::runfil
)
256 { $PDF::Reuse
::log .= "Jpeg~Blob~$iWidth~$iHeight\n";
258 $PDF::Reuse
::objRef
{$namnet} = $PDF::Reuse
::objNr
;
260 if (! $PDF::Reuse
::pos)
261 { errLog
("No output file, you have to call prFile first");
268 my $string_or_fileName = shift;
269 prJs
($string_or_fileName);
286 my $directory = shift;
287 prLogDir
($directory);
292 my ($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY) = @_;
293 prMbox
($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
304 my ($file, $pageNumber) = @_;
305 return prSinglePage
($file, $pageNumber);
310 my ($string, $font, $fontSize) = @_;
312 # replace font code with path to TTF font file if need be
313 my $ttf = C4
::Context
->config('ttf');
315 my $ttf_path = first
{ $_->{type
} eq $font } @
{ $ttf->{font
} };
316 if ( -e
$ttf_path->{content
} ) {
317 $font = $ttf_path->{content
};
319 warn "ERROR in koha-conf.xml -- missing <font type=\"$font\">/path/to/font.ttf</font>";
323 return prStrWidth
($string, $font, $fontSize);
328 my ($x, $y, $string, $align, $rotation) = @_;
329 return prText
($x, $y, $string, $align, $rotation);
335 return prTTFont
($path);
341 PDF
::Reuse
::Barcode
::Code128
(%opts);
347 PDF
::Reuse
::Barcode
::Code39
(%opts);
353 PDF
::Reuse
::Barcode
::COOP2of5
(%opts);
359 PDF
::Reuse
::Barcode
::EAN13
(%opts);
365 PDF
::Reuse
::Barcode
::EAN8
(%opts);
371 PDF
::Reuse
::Barcode
::IATA2of5
(%opts);
377 PDF
::Reuse
::Barcode
::Industrial2of5
(%opts);
383 PDF
::Reuse
::Barcode
::ITF
(%opts);
389 PDF
::Reuse
::Barcode
::Matrix2of5
(%opts);
395 PDF
::Reuse
::Barcode
::NW7
(%opts);
401 PDF
::Reuse
::Barcode
::UPCA
(%opts);
407 PDF
::Reuse
::Barcode
::UPCE
(%opts);
416 C4::Creators::PDF - A class wrapper for PDF::Reuse and PDF::Reuse::Barcode to allow usage as a psuedo-object. For usage see
417 PDF::Reuse documentation and C4::Creators::PDF code.
423 Chris Nighswonger <cnighswonger AT foundations DOT edu>