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 );
175 # this left aligns the spine label text, centering would be better,
176 # but word-wrapping breaks with centering on. :(
177 $pdf->setAlign('left');
179 # this sets the font size for the spine label text.
180 # if your text strings are extending past the right label border
181 # and arnt getting wrapped properly, reduce the font size some
182 # fyi: PDF::Report wont wrap continuious strings with no spaces in them, correctly
187 my $page_break_count = $startrow;
189 foreach $item (@resultsloop) {
193 $pdf->setAddTextPos( 36, ( $y_pos - 15 ) ); # INIT START POS
194 ( $hPos, $vPos ) = $pdf->getAddTextPos();
195 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
197 if ( $conf_data->{'dewey'} && $item->{'dewey'} ) {
199 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
200 $pdf->addText( $item->{'dewey'}, 10, 72, 90 );
201 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
205 if ( $conf_data->{'isbn'} && $item->{'isbn'} ) {
206 if ( $vPos1 == $vPos && $firstrow != 0 ) {
207 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
210 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
213 ( $hPos, $vPos ) = $pdf->getAddTextPos();
214 $pdf->addText( $item->{'isbn'}, 10, 72, 90 );
215 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
219 if ( $conf_data->{'class'} && $item->{'classification'} ) {
221 if ( $vPos1 == $vPos && $firstrow != 0 ) {
222 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
225 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
228 ( $hPos, $vPos ) = $pdf->getAddTextPos();
229 $pdf->addText( $item->{'classification'}, 10, 72, 90 );
230 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
234 if ( $conf_data->{'itemtype'} && $item->{'itemtype'} ) {
236 if ( $vPos1 == $vPos && $firstrow != 0 ) {
237 $pdf->setAddTextPos( 36, ( $vPos - 15 ) );
240 $pdf->setAddTextPos( 36, $vPos1 - 5 ); #add a space
243 ( $hPos, $vPos ) = $pdf->getAddTextPos();
244 $pdf->addText( $item->{'itemtype'}, 10, 72, 90 );
245 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
250 # $x_pos_spine, $y_pos,
251 # ( $x_pos_spine + $spine_width ),
252 # ( $y_pos - $label_height )
255 $y_pos = ( $y_pos - $label_height );
256 if ( $page_break_count == 8 ) {
258 $pdf->openpage($pagenumber);
260 $page_break_count = 0;
262 $y_pos = ( $y_pos_initial + 90 );
272 #------------------------------------------------
274 print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");
276 # draw boxes------------------
279 my $y_pos_initial = ( ( 792 - 36 ) - 90 );
280 my $y_pos = $y_pos_initial;
283 for ( $i = 1 ; $i <= 8 ; $i++ ) {
285 &drawbox( $x_pos_spine, $y_pos, ($spine_width), ($label_height) );
287 &drawbox( $x_pos_circ1, $y_pos, ($circ_width), ($label_height) );
288 &drawbox( $x_pos_circ2, $y_pos, ($circ_width), ($label_height) );
290 $y_pos = ( $y_pos - $label_height );
295 # draw boxes------------------
297 sub build_circ_barcode {
298 my ( $x_pos_circ, $y_pos, $value, $barcodetype ) = @_;
302 if ( $barcodetype eq 'EAN13' ) {
304 PDF::Reuse::Barcode::EAN13(
305 x => ( $x_pos_circ + 32 ),
306 y => ( $y_pos + 18 ),
315 $item->{'barcodeerror'} = 1;
319 elsif ( $barcodetype eq 'Code39' ) {
322 PDF::Reuse::Barcode::Code39(
323 x => ( $x_pos_circ + 9 ),
324 y => ( $y_pos + 15 ),
333 $item->{'barcodeerror'} = 1;
337 elsif ( $barcodetype eq 'Matrix2of5' ) {
340 PDF::Reuse::Barcode::Matrix2of5(
341 x => ( $x_pos_circ + 27 ),
342 y => ( $y_pos + 15 ),
352 $item->{'barcodeerror'} = 1;
356 elsif ( $barcodetype eq 'EAN8' ) {
359 PDF::Reuse::Barcode::EAN8(
360 x => ( $x_pos_circ + 42 ),
361 y => ( $y_pos + 15 ),
371 $item->{'barcodeerror'} = 1;
376 elsif ( $barcodetype eq 'UPC-E' ) {
378 PDF::Reuse::Barcode::UPCE(
379 x => ( $x_pos_circ + 27 ),
380 y => ( $y_pos + 15 ),
390 $item->{'barcodeerror'} = 1;
393 elsif ( $barcodetype eq 'NW7' ) {
395 PDF::Reuse::Barcode::NW7(
396 x => ( $x_pos_circ + 27 ),
397 y => ( $y_pos + 15 ),
407 $item->{'barcodeerror'} = 1;
410 elsif ( $barcodetype eq 'ITF' ) {
412 PDF::Reuse::Barcode::ITF(
413 x => ( $x_pos_circ + 27 ),
414 y => ( $y_pos + 15 ),
424 $item->{'barcodeerror'} = 1;
427 elsif ( $barcodetype eq 'Industrial2of5' ) {
429 PDF::Reuse::Barcode::Industrial2of5(
430 x => ( $x_pos_circ + 27 ),
431 y => ( $y_pos + 15 ),
440 $item->{'barcodeerror'} = 1;
443 elsif ( $barcodetype eq 'IATA2of5' ) {
445 PDF::Reuse::Barcode::IATA2of5(
446 x => ( $x_pos_circ + 27 ),
447 y => ( $y_pos + 15 ),
456 $item->{'barcodeerror'} = 1;
461 elsif ( $barcodetype eq 'COOP2of5' ) {
463 PDF::Reuse::Barcode::COOP2of5(
464 x => ( $x_pos_circ + 27 ),
465 y => ( $y_pos + 15 ),
474 $item->{'barcodeerror'} = 1;
477 elsif ( $barcodetype eq 'UPC-A' ) {
480 PDF::Reuse::Barcode::UPCA(
481 x => ( $x_pos_circ + 27 ),
482 y => ( $y_pos + 15 ),
491 $item->{'barcodeerror'} = 1;
496 #-----------------------------
499 my ( $llx, $lly, $urx, $ury ) = @_;
501 my $str = "q\n"; # save the graphic state
502 $str .= "1.0 0.0 0.0 RG\n"; # border color red
503 $str .= "1 1 1 rg\n"; # fill color blue
504 $str .= "$llx $lly $urx $ury re\n"; # a rectangle
505 $str .= "B\n"; # fill (and a little more)
506 $str .= "Q\n"; # save the graphic state