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;
26 use version; our $VERSION = qv('1.0.0_1');
37 my $type = ref($invocant) || $invocant;
40 _InitVars() if ($opts{InitVars} == 0);
41 _InitVars($opts{InitVars}) if ($opts{InitVars} > 0);
42 delete($opts{InitVars});
43 prDocDir($opts{'DocDir'}) if $opts{'DocDir'};
44 delete($opts{'DocDir'});
52 # if the pdf stream is utf8, explicitly set it to utf8; this avoids at lease some wide character errors -chris_n
53 utf8::encode($PDF::Reuse::stream) if utf8::is_utf8($PDF::Reuse::stream);
65 my $reference = shift;
66 prBookmark($reference);
71 my $directive = shift;
72 prCompress($directive);
84 return prDocForm(%params);
89 my ($pdfFile, $pageNo, $oldInternalName) = @_;
90 return prExtract($pdfFile, $pageNo, $oldInternalName);
95 my ($fieldName, $value) = @_;
96 prField($fieldName, $value);
101 my $fontName = shift;
102 return prFont($fontName);
108 return prFontSize($size);
114 return prForm(%params);
119 return prGetLogBuffer();
125 prGraphState($string);
131 return prImage(%params);
136 my ($string, $duplicateCode) = @_;
137 prInit($string, $duplicateCode);
142 my ($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat) = @_;
143 return prAltJpeg($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat);
148 my ($imageData, $width, $height, $imageFormat) = @_;
149 return prJpegBlob($imageData, $width, $height, $imageFormat);
152 # FIXME: This magick foo is an absolute hack until the maintainer of PDF::Reuse releases the next version which will include these features
155 { my ($iData, $iWidth, $iHeight, $iFormat,$aiData, $aiWidth, $aiHeight, $aiFormat) = @_;
156 my ($namnet, $utrad);
157 if (! $PDF::Reuse::pos) # If no output is active, it is no use to continue
160 prJpegBlob($aiData, $aiWidth, $aiHeight, $aiFormat);
161 my $altObjNr = $PDF::Reuse::objNr;
162 $PDF::Reuse::imageNr++;
163 $namnet = 'Ig' . $PDF::Reuse::imageNr;
164 $PDF::Reuse::objNr++;
165 $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos;
166 $utrad = "$PDF::Reuse::objNr 0 obj\n" .
167 "[ << /Image $altObjNr 0 R\n" .
168 "/DefaultForPrinting true\n" .
172 $PDF::Reuse::pos += syswrite *PDF::Reuse::UTFIL, $utrad;
173 if ($PDF::Reuse::runfil)
174 { $PDF::Reuse::log .= "Jpeg~AltImage\n";
176 $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
177 $namnet = prJpegBlob($iData, $iWidth, $iHeight, $iFormat, $PDF::Reuse::objNr);
178 if (! $PDF::Reuse::pos)
179 { errLog("No output file, you have to call prFile first");
185 { my ($iData, $iWidth, $iHeight, $iFormat, $altArrayObjNr) = @_;
186 my ($iLangd, $namnet, $utrad);
187 if (! $PDF::Reuse::pos) # If no output is active, it is no use to continue
190 my $checkidOld = $PDF::Reuse::checkId;
192 { my ($iFile, $checkId) = findGet($iData, $checkidOld);
194 { $iLangd = (stat($iFile))[7];
195 $PDF::Reuse::imageNr++;
196 $namnet = 'Ig' . $PDF::Reuse::imageNr;
197 $PDF::Reuse::objNr++;
198 $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos;
199 open (BILDFIL, "<$iFile") || errLog("Couldn't open $iFile, $!, aborts");
202 sysread BILDFIL, $iStream, $iLangd;
203 $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
204 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
205 ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
206 "/Filter/DCTDecode/ColorSpace/DeviceRGB"
207 . "/Length $iLangd >>stream\n$iStream\nendstream\nendobj\n";
209 $PDF::Reuse::pos += syswrite $PDF::Reuse::UTFIL, $utrad;
210 if ($PDF::Reuse::runfil)
211 { $PDF::Reuse::log .= "Cid~$PDF::Reuse::checkId\n";
212 $PDF::Reuse::log .= "Jpeg~$iFile~$iWidth~$iHeight\n";
214 $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
218 elsif ($iFormat == 1)
219 { my $iBlob = $iData;
220 $iLangd = length($iBlob);
221 $PDF::Reuse::imageNr++;
222 $namnet = 'Ig' . $PDF::Reuse::imageNr;
223 $PDF::Reuse::objNr++;
224 $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos;
225 $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
226 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
227 ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
228 "/Filter/DCTDecode/ColorSpace/DeviceRGB"
229 . "/Length $iLangd >>stream\n$iBlob\nendstream\nendobj\n";
230 $PDF::Reuse::pos += syswrite *PDF::Reuse::UTFIL, $utrad;
231 if ($PDF::Reuse::runfil)
232 { $PDF::Reuse::log .= "Jpeg~Blob~$iWidth~$iHeight\n";
234 $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
236 if (! $PDF::Reuse::pos)
237 { errLog("No output file, you have to call prFile first");
244 my $string_or_fileName = shift;
245 prJs($string_or_fileName);
262 my $directory = shift;
263 prLogDir($directory);
268 my ($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY) = @_;
269 prMbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
280 my ($file, $pageNumber) = @_;
281 return prSinglePage($file, $pageNumber);
286 my ($string, $font, $fontSize) = @_;
287 return prStrWidth($string, $font, $fontSize);
292 my ($x, $y, $string, $align, $rotation) = @_;
293 return prText($x, $y, $string, $align, $rotation);
299 return prTTFont($path);
305 PDF::Reuse::Barcode::Code128(%opts);
311 PDF::Reuse::Barcode::Code39(%opts);
317 PDF::Reuse::Barcode::COOP2of5(%opts);
323 PDF::Reuse::Barcode::EAN13(%opts);
329 PDF::Reuse::Barcode::EAN8(%opts);
335 PDF::Reuse::Barcode::IATA2of5(%opts);
341 PDF::Reuse::Barcode::Industrial2of5(%opts);
347 PDF::Reuse::Barcode::ITF(%opts);
353 PDF::Reuse::Barcode::Matrix2of5(%opts);
359 PDF::Reuse::Barcode::NW7(%opts);
365 PDF::Reuse::Barcode::UPCA(%opts);
371 PDF::Reuse::Barcode::UPCE(%opts);
380 C4::Creators::PDF - A class wrapper for PDF::Reuse and PDF::Reuse::Barcode to allow usage as a psuedo-object. For usage see
381 PDF::Reuse documentation and C4::Creators::PDF code.
387 Chris Nighswonger <cnighswonger AT foundations DOT edu>