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'});
63 my $reference = shift;
64 prBookmark($reference);
69 my $directive = shift;
70 prCompress($directive);
82 return prDocForm(%params);
87 my ($pdfFile, $pageNo, $oldInternalName) = @_;
88 return prExtract($pdfFile, $pageNo, $oldInternalName);
93 my ($fieldName, $value) = @_;
94 prField($fieldName, $value);
100 return prFont($fontName);
106 return prFontSize($size);
112 return prForm(%params);
117 return prGetLogBuffer();
123 prGraphState($string);
129 return prImage(%params);
134 my ($string, $duplicateCode) = @_;
135 prInit($string, $duplicateCode);
140 my ($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat) = @_;
141 return prAltJpeg($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat);
146 my ($imageData, $width, $height, $imageFormat) = @_;
147 return prJpegBlob($imageData, $width, $height, $imageFormat);
150 # FIXME: This magick foo is an absolute hack until the maintainer of PDF::Reuse releases the next version which will include these features
153 { my ($iData, $iWidth, $iHeight, $iFormat,$aiData, $aiWidth, $aiHeight, $aiFormat) = @_;
154 my ($namnet, $utrad);
155 if (! $PDF::Reuse::pos) # If no output is active, it is no use to continue
158 prJpegBlob($aiData, $aiWidth, $aiHeight, $aiFormat);
159 my $altObjNr = $PDF::Reuse::objNr;
160 $PDF::Reuse::imageNr++;
161 $namnet = 'Ig' . $PDF::Reuse::imageNr;
162 $PDF::Reuse::objNr++;
163 $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos;
164 $utrad = "$PDF::Reuse::objNr 0 obj\n" .
165 "[ << /Image $altObjNr 0 R\n" .
166 "/DefaultForPrinting true\n" .
170 $PDF::Reuse::pos += syswrite *PDF::Reuse::UTFIL, $utrad;
171 if ($PDF::Reuse::runfil)
172 { $PDF::Reuse::log .= "Jpeg~AltImage\n";
174 $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
175 $namnet = prJpegBlob($iData, $iWidth, $iHeight, $iFormat, $PDF::Reuse::objNr);
176 if (! $PDF::Reuse::pos)
177 { errLog("No output file, you have to call prFile first");
183 { my ($iData, $iWidth, $iHeight, $iFormat, $altArrayObjNr) = @_;
184 my ($iLangd, $namnet, $utrad);
185 if (! $PDF::Reuse::pos) # If no output is active, it is no use to continue
188 my $checkidOld = $PDF::Reuse::checkId;
190 { my ($iFile, $checkId) = findGet($iData, $checkidOld);
192 { $iLangd = (stat($iFile))[7];
193 $PDF::Reuse::imageNr++;
194 $namnet = 'Ig' . $PDF::Reuse::imageNr;
195 $PDF::Reuse::objNr++;
196 $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos;
197 open (BILDFIL, "<$iFile") || errLog("Couldn't open $iFile, $!, aborts");
200 sysread BILDFIL, $iStream, $iLangd;
201 $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
202 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
203 ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
204 "/Filter/DCTDecode/ColorSpace/DeviceRGB"
205 . "/Length $iLangd >>stream\n$iStream\nendstream\nendobj\n";
207 $PDF::Reuse::pos += syswrite $PDF::Reuse::UTFIL, $utrad;
208 if ($PDF::Reuse::runfil)
209 { $PDF::Reuse::log .= "Cid~$PDF::Reuse::checkId\n";
210 $PDF::Reuse::log .= "Jpeg~$iFile~$iWidth~$iHeight\n";
212 $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
216 elsif ($iFormat == 1)
217 { my $iBlob = $iData;
218 $iLangd = length($iBlob);
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 $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
224 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
225 ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
226 "/Filter/DCTDecode/ColorSpace/DeviceRGB"
227 . "/Length $iLangd >>stream\n$iBlob\nendstream\nendobj\n";
228 $PDF::Reuse::pos += syswrite *PDF::Reuse::UTFIL, $utrad;
229 if ($PDF::Reuse::runfil)
230 { $PDF::Reuse::log .= "Jpeg~Blob~$iWidth~$iHeight\n";
232 $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
234 if (! $PDF::Reuse::pos)
235 { errLog("No output file, you have to call prFile first");
242 my $string_or_fileName = shift;
243 prJs($string_or_fileName);
260 my $directory = shift;
261 prLogDir($directory);
266 my ($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY) = @_;
267 prMbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
278 my ($file, $pageNumber) = @_;
279 return prSinglePage($file, $pageNumber);
284 my ($string, $font, $fontSize) = @_;
285 return prStrWidth($string, $font, $fontSize);
290 my ($x, $y, $string, $align, $rotation) = @_;
291 return prText($x, $y, $string, $align, $rotation);
297 return prTTFont($path);
303 PDF::Reuse::Barcode::Code128(%opts);
309 PDF::Reuse::Barcode::Code39(%opts);
315 PDF::Reuse::Barcode::COOP2of5(%opts);
321 PDF::Reuse::Barcode::EAN13(%opts);
327 PDF::Reuse::Barcode::EAN8(%opts);
333 PDF::Reuse::Barcode::IATA2of5(%opts);
339 PDF::Reuse::Barcode::Industrial2of5(%opts);
345 PDF::Reuse::Barcode::ITF(%opts);
351 PDF::Reuse::Barcode::Matrix2of5(%opts);
357 PDF::Reuse::Barcode::NW7(%opts);
363 PDF::Reuse::Barcode::UPCA(%opts);
369 PDF::Reuse::Barcode::UPCE(%opts);
378 C4::Creators::PDF - A class wrapper for PDF::Reuse and PDF::Reuse::Barcode to allow usage as a psuedo-object. For usage see
379 PDF::Reuse documentation and C4::Creators::PDF code.
385 Chris Nighswonger <cnighswonger AT foundations DOT edu>