7 use C4::Interface::CGI::Output;
11 use PDF::Reuse::Barcode;
14 my $htdocs_path = C4::Context->config('intrahtdocs');
19 #--------------------------------------------------------
20 # get the printing settings
22 my $dbh = C4::Context->dbh;
23 my $query2 = " SELECT * FROM labels_conf LIMIT 1 ";
24 my $sth = $dbh->prepare($query2);
27 my $conf_data = $sth->fetchrow_hashref;
29 # get barcode type from $conf_data
30 my $barcodetype = $conf_data->{'barcodetype'};
31 my $startrow = $conf_data->{'startrow'};
37 # get the actual items to be printed.
39 my $query3 = " Select * from labels ";
40 my $sth = $dbh->prepare($query3);
45 while ( my $data = $sth->fetchrow_hashref ) {
47 # lets get some summary info from each item
49 " select *from biblio, biblioitems, items where itemnumber = ? and
50 items.biblioitemnumber=biblioitems.biblioitemnumber and
51 biblioitems.biblionumber=biblio.biblionumber";
53 my $sth1 = $dbh->prepare($query1);
54 $sth1->execute( $data->{'itemnumber'} );
55 my $data1 = $sth1->fetchrow_hashref();
57 push( @resultsloop, $data1 );
64 # dimensions of gaylord paper
67 my $upperRightX = 612;
68 my $upperRightY = 792;
70 #----------------------------------
71 # setting up the pdf doc
73 prFile("$htdocs_path/barcodes/new.pdf");
74 prLogDir("$htdocs_path/barcodes");
76 #prMbox ( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
77 prMbox( 0, 0, 612, 792 );
79 prFont('Times-Roman'); # Just setting a font
84 my $label_height = 90;
90 my $x_pos_circ1 = 135;
91 my $x_pos_circ2 = 369;
95 my $y_pos_initial = ( ( $pageheight - $margin ) - $label_height );
96 my $y_pos_initial_startrow =
97 ( ( $pageheight - $margin ) - ( $label_height * $startrow ) );
99 my $y_pos_initial = ( ( 792 - 36 ) - 90 );
101 my $y_pos = $y_pos_initial_startrow;
103 #my $y_pos = $y_pos_initial;
105 my $page_break_count = $startrow;
106 my $codetype = 'Code39';
108 # do border---------------
109 my $str = "q\n"; # save the graphic state
110 $str .= "4 w\n"; # border color red
111 $str .= "0.0 0.0 0.0 RG\n"; # border color red
112 $str .= "1 1 1 rg\n"; # fill color blue
113 $str .= "0 0 612 792 re\n"; # a rectangle
114 $str .= "B\n"; # fill (and a little more)
115 $str .= "Q\n"; # save the graphic state
117 # do border---------------
123 foreach $item (@resultsloop) {
129 #building up spine text
131 my $line_spacer = 16;
133 build_circ_barcode( $x_pos_circ1, $y_pos, $item->{'barcode'},
134 $conf_data->{'barcodetype'} );
135 build_circ_barcode( $x_pos_circ2, $y_pos, $item->{'barcode'},
136 $conf_data->{'barcodetype'} );
138 # added for xpdf compat. doesnt use type3 fonts., but increases filesize from 20k to 200k
139 # i think its embedding extra fonts in the pdf file.
142 $y_pos = ( $y_pos - $label_height );
144 # the gaylord labels have 8 rows per sheet, this pagebreaks after 8 rows
145 if ( $page_break_count == 8 ) {
148 $page_break_count = 0;
150 $y_pos = $y_pos_initial;
158 #----------------------------------------------------------------------------
161 $file = "$htdocs_path/barcodes/new.pdf";
163 my $pdf = new PDF::Report( File => $file );
165 # my $pdf = new PDF::Report(PageSize => "letter",
166 # PageOrientation => "Landscape");
168 #$pdf->newpage($nopage);
170 $pdf->openpage($pagenumber);
172 ( $pagewidth, $pageheight ) = $pdf->getPageDimensions();
173 my $y_pos = ( $y_pos_initial_startrow + 90 );
174 $pdf->setAlign('left');
177 my $page_break_count = $startrow;
179 foreach $item (@resultsloop) {
183 $pdf->setAddTextPos( 36, ( $y_pos - 15 ) ); # INIT START POS
184 ( $hPos, $vPos ) = $pdf->getAddTextPos();
185 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
187 if ( $conf_data->{'dewey'} && $item->{'dewey'} ) {
189 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
190 $pdf->addText( $item->{'dewey'}, 10, 72, 90 );
191 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
195 if ( $conf_data->{'isbn'} && $item->{'isbn'} ) {
196 if ( $vPos1 == $vPos && $firstrow != 0 ) {
197 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
200 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
203 ( $hPos, $vPos ) = $pdf->getAddTextPos();
204 $pdf->addText( $item->{'isbn'}, 10, 72, 90 );
205 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
209 if ( $conf_data->{'class'} && $item->{'classification'} ) {
211 if ( $vPos1 == $vPos && $firstrow != 0 ) {
212 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
215 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
218 ( $hPos, $vPos ) = $pdf->getAddTextPos();
219 $pdf->addText( $item->{'classification'}, 10, 72, 90 );
220 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
224 if ( $conf_data->{'itemtype'} && $item->{'itemtype'} ) {
226 if ( $vPos1 == $vPos && $firstrow != 0 ) {
227 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
230 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
233 ( $hPos, $vPos ) = $pdf->getAddTextPos();
234 $pdf->addText( $item->{'itemtype'}, 10, 72, 90 );
235 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
240 # $x_pos_spine, $y_pos,
241 # ( $x_pos_spine + $spine_width ),
242 # ( $y_pos - $label_height )
245 $y_pos = ( $y_pos - $label_height );
246 if ( $page_break_count == 8 ) {
248 $pdf->openpage($pagenumber);
250 $page_break_count = 0;
252 $y_pos = ( $y_pos_initial + 90 );
262 #------------------------------------------------
264 print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");
266 # draw boxes------------------
269 my $y_pos_initial = ( ( 792 - 36 ) - 90 );
270 my $y_pos = $y_pos_initial;
273 for ( $i = 1 ; $i <= 8 ; $i++ ) {
275 &drawbox( $x_pos_spine, $y_pos, ($spine_width), ($label_height) );
277 &drawbox( $x_pos_circ1, $y_pos, ($circ_width), ($label_height) );
278 &drawbox( $x_pos_circ2, $y_pos, ($circ_width), ($label_height) );
280 $y_pos = ( $y_pos - $label_height );
285 # draw boxes------------------
287 sub build_circ_barcode {
288 my ( $x_pos_circ, $y_pos, $value, $barcodetype ) = @_;
292 if ( $barcodetype eq 'EAN13' ) {
294 PDF::Reuse::Barcode::EAN13(
295 x => ( $x_pos_circ + 32 ),
296 y => ( $y_pos + 18 ),
305 $item->{'barcodeerror'} = 1;
309 elsif ( $barcodetype eq 'Code39' ) {
312 PDF::Reuse::Barcode::Code39(
313 x => ( $x_pos_circ + 9 ),
314 y => ( $y_pos + 15 ),
323 $item->{'barcodeerror'} = 1;
327 elsif ( $barcodetype eq 'Matrix2of5' ) {
330 PDF::Reuse::Barcode::Matrix2of5(
331 x => ( $x_pos_circ + 27 ),
332 y => ( $y_pos + 15 ),
342 $item->{'barcodeerror'} = 1;
346 elsif ( $barcodetype eq 'EAN8' ) {
349 PDF::Reuse::Barcode::EAN8(
350 x => ( $x_pos_circ + 42 ),
351 y => ( $y_pos + 15 ),
361 $item->{'barcodeerror'} = 1;
366 elsif ( $barcodetype eq 'UPC-E' ) {
368 PDF::Reuse::Barcode::UPCE(
369 x => ( $x_pos_circ + 27 ),
370 y => ( $y_pos + 15 ),
380 $item->{'barcodeerror'} = 1;
383 elsif ( $barcodetype eq 'NW7' ) {
385 PDF::Reuse::Barcode::NW7(
386 x => ( $x_pos_circ + 27 ),
387 y => ( $y_pos + 15 ),
397 $item->{'barcodeerror'} = 1;
400 elsif ( $barcodetype eq 'ITF' ) {
402 PDF::Reuse::Barcode::ITF(
403 x => ( $x_pos_circ + 27 ),
404 y => ( $y_pos + 15 ),
414 $item->{'barcodeerror'} = 1;
417 elsif ( $barcodetype eq 'Industrial2of5' ) {
419 PDF::Reuse::Barcode::Industrial2of5(
420 x => ( $x_pos_circ + 27 ),
421 y => ( $y_pos + 15 ),
430 $item->{'barcodeerror'} = 1;
433 elsif ( $barcodetype eq 'IATA2of5' ) {
435 PDF::Reuse::Barcode::IATA2of5(
436 x => ( $x_pos_circ + 27 ),
437 y => ( $y_pos + 15 ),
446 $item->{'barcodeerror'} = 1;
451 elsif ( $barcodetype eq 'COOP2of5' ) {
453 PDF::Reuse::Barcode::COOP2of5(
454 x => ( $x_pos_circ + 27 ),
455 y => ( $y_pos + 15 ),
464 $item->{'barcodeerror'} = 1;
467 elsif ( $barcodetype eq 'UPC-A' ) {
470 PDF::Reuse::Barcode::UPCA(
471 x => ( $x_pos_circ + 27 ),
472 y => ( $y_pos + 15 ),
481 $item->{'barcodeerror'} = 1;
486 #-----------------------------
489 my ( $llx, $lly, $urx, $ury ) = @_;
491 my $str = "q\n"; # save the graphic state
492 $str .= "1.0 0.0 0.0 RG\n"; # border color red
493 $str .= "1 1 1 rg\n"; # fill color blue
494 $str .= "$llx $lly $urx $ury re\n"; # a rectangle
495 $str .= "B\n"; # fill (and a little more)
496 $str .= "Q\n"; # save the graphic state