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
;
27 use version
; our $VERSION = qv
('3.07.00.049');
38 my $type = ref($invocant) || $invocant;
41 _InitVars
() if ($opts{InitVars
} == 0);
42 _InitVars
($opts{InitVars
}) if ($opts{InitVars
} > 0);
43 delete($opts{InitVars
});
44 prDocDir
($opts{'DocDir'}) if $opts{'DocDir'};
45 delete($opts{'DocDir'});
47 my $fh = File
::Temp
->new( UNLINK
=> 0, SUFFIX
=> '.pdf' );
48 $opts{Name
} = $self->{filename
} = "$fh"; # filename
49 close $fh; # we need just filename
58 # if the pdf stream is utf8, explicitly set it to utf8; this avoids at lease some wide character errors -chris_n
59 utf8
::encode
($PDF::Reuse
::stream
) if utf8
::is_utf8
($PDF::Reuse
::stream
);
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;
115 return prFont
($fontName);
121 return prFontSize
($size);
127 return prForm
(%params);
132 return prGetLogBuffer
();
138 prGraphState
($string);
144 return prImage
(%params);
149 my ($string, $duplicateCode) = @_;
150 prInit
($string, $duplicateCode);
155 my ($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat) = @_;
156 return prAltJpeg
($imageData, $width, $height, $imageFormat, $altImageData, $altImageWidth, $altImageHeight, $altImageFormat);
161 my ($imageData, $width, $height, $imageFormat) = @_;
162 return prJpegBlob
($imageData, $width, $height, $imageFormat);
165 # FIXME: This magick foo is an absolute hack until the maintainer of PDF::Reuse releases the next version which will include these features
168 { my ($iData, $iWidth, $iHeight, $iFormat,$aiData, $aiWidth, $aiHeight, $aiFormat) = @_;
169 my ($namnet, $utrad);
170 if (! $PDF::Reuse
::pos) # If no output is active, it is no use to continue
173 prJpegBlob
($aiData, $aiWidth, $aiHeight, $aiFormat);
174 my $altObjNr = $PDF::Reuse
::objNr
;
175 $PDF::Reuse
::imageNr
++;
176 $namnet = 'Ig' . $PDF::Reuse
::imageNr
;
177 $PDF::Reuse
::objNr
++;
178 $PDF::Reuse
::objekt
[$PDF::Reuse
::objNr
] = $PDF::Reuse
::pos;
179 $utrad = "$PDF::Reuse::objNr 0 obj\n" .
180 "[ << /Image $altObjNr 0 R\n" .
181 "/DefaultForPrinting true\n" .
185 $PDF::Reuse
::pos += syswrite *PDF
::Reuse
::UTFIL
, $utrad;
186 if ($PDF::Reuse
::runfil
)
187 { $PDF::Reuse
::log .= "Jpeg~AltImage\n";
189 $PDF::Reuse
::objRef
{$namnet} = $PDF::Reuse
::objNr
;
190 $namnet = prJpegBlob
($iData, $iWidth, $iHeight, $iFormat, $PDF::Reuse
::objNr
);
191 if (! $PDF::Reuse
::pos)
192 { errLog
("No output file, you have to call prFile first");
198 { my ($iData, $iWidth, $iHeight, $iFormat, $altArrayObjNr) = @_;
199 my ($iLangd, $namnet, $utrad);
200 if (! $PDF::Reuse
::pos) # If no output is active, it is no use to continue
203 my $checkidOld = $PDF::Reuse
::checkId
;
205 { my ($iFile, $checkId) = findGet
($iData, $checkidOld);
207 { $iLangd = (stat($iFile))[7];
208 $PDF::Reuse
::imageNr
++;
209 $namnet = 'Ig' . $PDF::Reuse
::imageNr
;
210 $PDF::Reuse
::objNr
++;
211 $PDF::Reuse
::objekt
[$PDF::Reuse
::objNr
] = $PDF::Reuse
::pos;
212 open (BILDFIL
, "<$iFile") || errLog
("Couldn't open $iFile, $!, aborts");
215 sysread BILDFIL
, $iStream, $iLangd;
216 $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
217 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
218 ($altArrayObjNr ?
"/Alternates $altArrayObjNr 0 R " : "") .
219 "/Filter/DCTDecode/ColorSpace/DeviceRGB"
220 . "/Length $iLangd >>stream\n$iStream\nendstream\nendobj\n";
222 $PDF::Reuse
::pos += syswrite $PDF::Reuse
::UTFIL
, $utrad;
223 if ($PDF::Reuse
::runfil
)
224 { $PDF::Reuse
::log .= "Cid~$PDF::Reuse::checkId\n";
225 $PDF::Reuse
::log .= "Jpeg~$iFile~$iWidth~$iHeight\n";
227 $PDF::Reuse
::objRef
{$namnet} = $PDF::Reuse
::objNr
;
231 elsif ($iFormat == 1)
232 { my $iBlob = $iData;
233 $iLangd = length($iBlob);
234 $PDF::Reuse
::imageNr
++;
235 $namnet = 'Ig' . $PDF::Reuse
::imageNr
;
236 $PDF::Reuse
::objNr
++;
237 $PDF::Reuse
::objekt
[$PDF::Reuse
::objNr
] = $PDF::Reuse
::pos;
238 $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
239 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
240 ($altArrayObjNr ?
"/Alternates $altArrayObjNr 0 R " : "") .
241 "/Filter/DCTDecode/ColorSpace/DeviceRGB"
242 . "/Length $iLangd >>stream\n$iBlob\nendstream\nendobj\n";
243 $PDF::Reuse
::pos += syswrite *PDF
::Reuse
::UTFIL
, $utrad;
244 if ($PDF::Reuse
::runfil
)
245 { $PDF::Reuse
::log .= "Jpeg~Blob~$iWidth~$iHeight\n";
247 $PDF::Reuse
::objRef
{$namnet} = $PDF::Reuse
::objNr
;
249 if (! $PDF::Reuse
::pos)
250 { errLog
("No output file, you have to call prFile first");
257 my $string_or_fileName = shift;
258 prJs
($string_or_fileName);
275 my $directory = shift;
276 prLogDir
($directory);
281 my ($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY) = @_;
282 prMbox
($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
293 my ($file, $pageNumber) = @_;
294 return prSinglePage
($file, $pageNumber);
299 my ($string, $font, $fontSize) = @_;
300 return prStrWidth
($string, $font, $fontSize);
305 my ($x, $y, $string, $align, $rotation) = @_;
306 return prText
($x, $y, $string, $align, $rotation);
312 return prTTFont
($path);
318 PDF
::Reuse
::Barcode
::Code128
(%opts);
324 PDF
::Reuse
::Barcode
::Code39
(%opts);
330 PDF
::Reuse
::Barcode
::COOP2of5
(%opts);
336 PDF
::Reuse
::Barcode
::EAN13
(%opts);
342 PDF
::Reuse
::Barcode
::EAN8
(%opts);
348 PDF
::Reuse
::Barcode
::IATA2of5
(%opts);
354 PDF
::Reuse
::Barcode
::Industrial2of5
(%opts);
360 PDF
::Reuse
::Barcode
::ITF
(%opts);
366 PDF
::Reuse
::Barcode
::Matrix2of5
(%opts);
372 PDF
::Reuse
::Barcode
::NW7
(%opts);
378 PDF
::Reuse
::Barcode
::UPCA
(%opts);
384 PDF
::Reuse
::Barcode
::UPCE
(%opts);
393 C4::Creators::PDF - A class wrapper for PDF::Reuse and PDF::Reuse::Barcode to allow usage as a psuedo-object. For usage see
394 PDF::Reuse documentation and C4::Creators::PDF code.
400 Chris Nighswonger <cnighswonger AT foundations DOT edu>