7 use C4::Interface::CGI::Output;
11 use PDF::Reuse::Barcode;
13 my $htdocs_path = C4::Context->config('intrahtdocs');
18 #--------------------------------------------------------
19 # get the printing settings
21 my $dbh = C4::Context->dbh;
22 my $query2 = " SELECT * FROM labels_conf LIMIT 1 ";
23 my $sth = $dbh->prepare($query2);
26 my $conf_data = $sth->fetchrow_hashref;
28 # get barcode type from $conf_data
29 my $barcodetype = $conf_data->{'barcodetype'};
30 my $startrow = $conf_data->{'startrow'};
36 # get the actual items to be printed.
38 my $query3 = " Select * from labels ";
39 my $sth = $dbh->prepare($query3);
44 while ( my $data = $sth->fetchrow_hashref ) {
46 # lets get some summary info from each item
48 " select *from biblio, biblioitems, items where itemnumber = ? and
49 items.biblioitemnumber=biblioitems.biblioitemnumber and
50 biblioitems.biblionumber=biblio.biblionumber";
52 my $sth1 = $dbh->prepare($query1);
53 $sth1->execute( $data->{'itemnumber'} );
54 my $data1 = $sth1->fetchrow_hashref();
56 push( @resultsloop, $data1 );
63 # dimensions of gaylord paper
66 my $upperRightX = 612;
67 my $upperRightY = 792;
69 #----------------------------------
70 # setting up the pdf doc
72 prFile("$htdocs_path/barcodes/new.pdf");
73 prLogDir("$htdocs_path/barcodes");
75 #prMbox ( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
76 prMbox( 0, 0, 612, 792 );
78 prFont('Times-Roman'); # Just setting a font
83 my $label_height = 90;
89 my $x_pos_circ1 = 135;
90 my $x_pos_circ2 = 369;
94 my $y_pos_initial = ( ( $pageheight - $margin ) - $label_height );
95 my $y_pos_initial_startrow =
96 ( ( $pageheight - $margin ) - ( $label_height * $startrow ) );
98 my $y_pos_initial = ( ( 792 - 36 ) - 90 );
100 my $y_pos = $y_pos_initial_startrow;
102 #my $y_pos = $y_pos_initial;
104 my $page_break_count = $startrow;
105 my $codetype = 'Code39';
107 # do border---------------
108 my $str = "q\n"; # save the graphic state
109 $str .= "4 w\n"; # border color red
110 $str .= "0.0 0.0 0.0 RG\n"; # border color red
111 $str .= "1 1 1 rg\n"; # fill color blue
112 $str .= "0 0 612 792 re\n"; # a rectangle
113 $str .= "B\n"; # fill (and a little more)
114 $str .= "Q\n"; # save the graphic state
116 # do border---------------
122 foreach $item (@resultsloop) {
128 #building up spine text
130 my $line_spacer = 16;
132 build_circ_barcode( $x_pos_circ1, $y_pos, $item->{'barcode'},
133 $conf_data->{'barcodetype'} );
134 build_circ_barcode( $x_pos_circ2, $y_pos, $item->{'barcode'},
135 $conf_data->{'barcodetype'} );
137 # added for xpdf compat. doesnt use type3 fonts., but increases filesize from 20k to 200k
138 # i think its embedding extra fonts in the pdf file.
141 $y_pos = ( $y_pos - $label_height );
143 # the gaylord labels have 8 rows per sheet, this pagebreaks after 8 rows
144 if ( $page_break_count == 8 ) {
147 $page_break_count = 0;
149 $y_pos = $y_pos_initial;
157 #----------------------------------------------------------------------------
162 $file = '/usr/local/opus-dev/intranet/htdocs/intranet-tmpl/barcodes/new.pdf';
165 my $pdf = new PDF::Report( File => $file );
167 # my $pdf = new PDF::Report(PageSize => "letter",
168 # PageOrientation => "Landscape");
170 #$pdf->newpage($nopage);
172 $pdf->openpage($pagenumber);
174 ( $pagewidth, $pageheight ) = $pdf->getPageDimensions();
175 my $y_pos = ( $y_pos_initial_startrow + 90 );
176 $pdf->setAlign('left');
179 my $page_break_count = $startrow;
181 foreach $item (@resultsloop) {
185 $pdf->setAddTextPos( 36, ( $y_pos - 15 ) ); # INIT START POS
186 ( $hPos, $vPos ) = $pdf->getAddTextPos();
187 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
189 if ( $conf_data->{'dewey'} && $item->{'dewey'} ) {
191 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
192 $pdf->addText( $item->{'dewey'}, 10, 72, 90 );
193 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
197 if ( $conf_data->{'isbn'} && $item->{'isbn'} ) {
198 if ( $vPos1 == $vPos && $firstrow != 0 ) {
199 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
202 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
205 ( $hPos, $vPos ) = $pdf->getAddTextPos();
206 $pdf->addText( $item->{'isbn'}, 10, 72, 90 );
207 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
211 if ( $conf_data->{'class'} && $item->{'classification'} ) {
213 if ( $vPos1 == $vPos && $firstrow != 0 ) {
214 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
217 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
220 ( $hPos, $vPos ) = $pdf->getAddTextPos();
221 $pdf->addText( $item->{'classification'}, 10, 72, 90 );
222 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
226 if ( $conf_data->{'itemtype'} && $item->{'itemtype'} ) {
228 if ( $vPos1 == $vPos && $firstrow != 0 ) {
229 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
232 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
235 ( $hPos, $vPos ) = $pdf->getAddTextPos();
236 $pdf->addText( $item->{'itemtype'}, 10, 72, 90 );
237 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
242 # $x_pos_spine, $y_pos,
243 # ( $x_pos_spine + $spine_width ),
244 # ( $y_pos - $label_height )
247 $y_pos = ( $y_pos - $label_height );
248 if ( $page_break_count == 8 ) {
250 $pdf->openpage($pagenumber);
252 $page_break_count = 0;
254 $y_pos = ( $y_pos_initial + 90 );
264 #------------------------------------------------
266 print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");
268 # draw boxes------------------
271 my $y_pos_initial = ( ( 792 - 36 ) - 90 );
272 my $y_pos = $y_pos_initial;
275 for ( $i = 1 ; $i <= 8 ; $i++ ) {
277 &drawbox( $x_pos_spine, $y_pos, ($spine_width), ($label_height) );
279 &drawbox( $x_pos_circ1, $y_pos, ($circ_width), ($label_height) );
280 &drawbox( $x_pos_circ2, $y_pos, ($circ_width), ($label_height) );
282 $y_pos = ( $y_pos - $label_height );
287 # draw boxes------------------
289 sub build_circ_barcode {
290 my ( $x_pos_circ, $y_pos, $value, $barcodetype ) = @_;
294 if ( $barcodetype eq 'EAN13' ) {
296 PDF::Reuse::Barcode::EAN13(
297 x => ( $x_pos_circ + 32 ),
298 y => ( $y_pos + 18 ),
307 $item->{'barcodeerror'} = 1;
311 elsif ( $barcodetype eq 'Code39' ) {
314 PDF::Reuse::Barcode::Code39(
315 x => ( $x_pos_circ + 9 ),
316 y => ( $y_pos + 15 ),
325 $item->{'barcodeerror'} = 1;
329 elsif ( $barcodetype eq 'Matrix2of5' ) {
332 PDF::Reuse::Barcode::Matrix2of5(
333 x => ( $x_pos_circ + 27 ),
334 y => ( $y_pos + 15 ),
344 $item->{'barcodeerror'} = 1;
348 elsif ( $barcodetype eq 'EAN8' ) {
351 PDF::Reuse::Barcode::EAN8(
352 x => ( $x_pos_circ + 42 ),
353 y => ( $y_pos + 15 ),
363 $item->{'barcodeerror'} = 1;
368 elsif ( $barcodetype eq 'UPC-E' ) {
370 PDF::Reuse::Barcode::UPCE(
371 x => ( $x_pos_circ + 27 ),
372 y => ( $y_pos + 15 ),
382 $item->{'barcodeerror'} = 1;
385 elsif ( $barcodetype eq 'NW7' ) {
387 PDF::Reuse::Barcode::NW7(
388 x => ( $x_pos_circ + 27 ),
389 y => ( $y_pos + 15 ),
399 $item->{'barcodeerror'} = 1;
402 elsif ( $barcodetype eq 'ITF' ) {
404 PDF::Reuse::Barcode::ITF(
405 x => ( $x_pos_circ + 27 ),
406 y => ( $y_pos + 15 ),
416 $item->{'barcodeerror'} = 1;
419 elsif ( $barcodetype eq 'Industrial2of5' ) {
421 PDF::Reuse::Barcode::Industrial2of5(
422 x => ( $x_pos_circ + 27 ),
423 y => ( $y_pos + 15 ),
432 $item->{'barcodeerror'} = 1;
435 elsif ( $barcodetype eq 'IATA2of5' ) {
437 PDF::Reuse::Barcode::IATA2of5(
438 x => ( $x_pos_circ + 27 ),
439 y => ( $y_pos + 15 ),
448 $item->{'barcodeerror'} = 1;
453 elsif ( $barcodetype eq 'COOP2of5' ) {
455 PDF::Reuse::Barcode::COOP2of5(
456 x => ( $x_pos_circ + 27 ),
457 y => ( $y_pos + 15 ),
466 $item->{'barcodeerror'} = 1;
469 elsif ( $barcodetype eq 'UPC-A' ) {
472 PDF::Reuse::Barcode::UPCA(
473 x => ( $x_pos_circ + 27 ),
474 y => ( $y_pos + 15 ),
483 $item->{'barcodeerror'} = 1;
488 #-----------------------------
491 my ( $llx, $lly, $urx, $ury ) = @_;
493 my $str = "q\n"; # save the graphic state
494 $str .= "1.0 0.0 0.0 RG\n"; # border color red
495 $str .= "1 1 1 rg\n"; # fill color blue
496 $str .= "$llx $lly $urx $ury re\n"; # a rectangle
497 $str .= "B\n"; # fill (and a little more)
498 $str .= "Q\n"; # save the graphic state