3 #----------------------------------------------------------------------
4 # this script is really divided into 2 differenvt section,
6 # the first section creates, and defines the new PDF file the barcodes
7 # using PDF::Reuse::Barcode, then saves the file to disk.
9 # the second section then opens the pdf file off disk, and places the spline label
10 # text in the left-most column of the page. then save the file again.
12 # the reason for this goofyness, it that i couldnt find a single perl package that handled both barcodes and decent text placement.
14 #use lib '/usr/local/hlt/intranet/modules';
15 #use C4::Context("/etc/koha-hlt.conf");
23 use C4::Interface::CGI::Output;
27 use PDF::Reuse::Barcode;
34 my $htdocs_path = C4::Context->config('intrahtdocs');
39 # get the printing settings
41 my $conf_data = get_label_options();
42 my @resultsloop = get_label_items();
44 warn Dumper $conf_data;
47 my $barcodetype = $conf_data->{'barcodetype'};
48 my $printingtype = $conf_data->{'printingtype'};
49 my $guidebox = $conf_data->{'guidebox'};
50 my $startrow = $conf_data->{'startrow'};
53 $printingtype = 'both';
60 #warn Dumper @resultsloop;
62 # dimensions of gaylord paper
65 my $upperRightX = 612;
66 my $upperRightY = 792;
68 #----------------------------------
69 # setting up the pdf doc
71 #remove the file before write, for testing
72 unlink "$htdocs_path/barcodes/new.pdf";
74 prFile("$htdocs_path/barcodes/new.pdf");
75 prLogDir("$htdocs_path/barcodes");
77 #prMbox ( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
78 prMbox( 0, 0, 612, 792 );
80 prFont('Times-Roman'); # Just setting a font
85 my $label_height = 90;
91 my $x_pos_circ1 = 135;
92 my $x_pos_circ2 = 369;
96 warn "STARTROW = $startrow\n";
98 #my $y_pos_initial = ( ( 792 - 36 ) - 90 );
99 my $y_pos_initial = ( ( $pageheight - $margin ) - $label_height );
100 my $y_pos_initial_startrow =
101 ( ( $pageheight - $margin ) - ( $label_height * $startrow ) );
103 my $y_pos = $y_pos_initial_startrow;
105 warn "Y POS INITAL : $y_pos_initial";
106 warn "Y POS : $y_pos";
107 warn "Y START ROW = $y_pos_initial_startrow";
110 my $page_break_count = $startrow;
111 my $codetype = 'Code39';
113 # do border---------------
114 my $str = "q\n"; # save the graphic state
115 $str .= "4 w\n"; # border color red
116 $str .= "0.0 0.0 0.0 RG\n"; # border color red
117 $str .= "1 1 1 rg\n"; # fill color blue
118 $str .= "0 0 612 792 re\n"; # a rectangle
119 $str .= "B\n"; # fill (and a little more)
120 $str .= "Q\n"; # save the graphic state
122 # do border---------------
130 foreach $item (@resultsloop) {
131 if ( $i2 == 1 && $guidebox == 1) {
133 $x_pos_spine, $x_pos_circ1, $x_pos_circ2, $y_pos,
134 $spine_width, $label_height, $circ_width
138 #warn Dumper $item->{'itemtype'};
139 #warn "COUNT = $cnt1";
141 #building up spine text
143 my $line_spacer = 16;
148 "COUNT=$i2, PBREAKCNT=$page_break_count, X,Y POS x=$x_pos_circ1, y=$y_pos";
149 if ( $printingtype eq 'barcode' || $printingtype eq 'both' ) {
150 build_circ_barcode( $x_pos_circ1, $y_pos, $item->{'barcode'},
151 $conf_data->{'barcodetype'}, \$item );
152 build_circ_barcode( $x_pos_circ2, $y_pos, $item->{'barcode'},
153 $conf_data->{'barcodetype'}, \$item );
155 # added for xpdf compat. doesnt use type3 fonts., but increases filesize from 20k to 200k
156 # i think its embedding extra fonts in the pdf file.
159 $y_pos = ( $y_pos - $label_height );
161 # the gaylord labels have 8 rows per sheet, this pagebreaks after 8 rows
162 if ( $page_break_count == 8 ) {
165 #warn "############# PAGEBREAK ###########";
166 $page_break_count = 0;
168 $y_pos = $y_pos_initial;
173 ############## end of loop
178 #----------------------------------------------------------------------------
179 # this second section of the script uses a diff perl class than the previous section
180 # it opens the 'new.pdf' file that the previous section has just saved
182 if ( $printingtype eq 'spine' || $printingtype eq 'both' ) {
184 $file = "$htdocs_path/barcodes/new.pdf";
186 my $pdf = new PDF::Report( File => $file );
188 # my $pdf = new PDF::Report(PageSize => "letter",
189 # PageOrientation => "Landscape");
191 #$pdf->newpage($nopage);
193 $pdf->openpage($pagenumber);
195 ( $pagewidth, $pageheight ) = $pdf->getPageDimensions();
197 #warn "PAGE DIM = $pagewidth, $pageheight";
198 #warn "Y START ROW = $y_pos_initial_startrow";
199 my $y_pos = ( $y_pos_initial_startrow + 90 );
201 #my $y_pos = ( $y_pos_initial_startrow );
202 #warn "Y POS = $y_pos";
204 # now needed now we are using centerString().
205 #$pdf->setAlign('left');
210 my $page_break_count = $startrow;
212 #warn "INIT PAGEBREAK COUNT = $page_break_count";
214 #warn "#----------------------------------\n";
215 #warn "INIT VPOS = $vPos, hPos = $hPos";
218 my $start_text_pos = 39; # ( 36 - 5 = 31 ) 5 is an inside border for text.
219 my $spine_label_text_with = 67;
221 foreach $item (@resultsloop) {
224 #warn "START Y_POS=$y_pos";
227 $pdf->setAddTextPos( $start_text_pos, ( $y_pos - 20 ) )
229 ( $hPos, $vPos ) = $pdf->getAddTextPos();
231 my $hPosEnd = ( $hPos + $spine_label_text_with ); # 72
232 if ( $conf_data->{'dewey'} && $item->{'dewey'} ) {
233 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
234 $pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'dewey'} );
235 $vPos = $vPos - $vPosSpacer;
238 if ( $conf_data->{'isbn'} && $item->{'isbn'} ) {
239 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
240 $pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'isbn'} );
241 $vPos = $vPos - $vPosSpacer;
244 if ( $conf_data->{'class'} && $item->{'classification'} ) {
245 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
246 $pdf->centerString( $hPos, $hPosEnd, $vPos,
247 $item->{'classification'} );
248 $vPos = $vPos - $vPosSpacer;
251 if ( $conf_data->{'itemtype'} && $item->{'itemtype'} ) {
252 ( $hPos, $vPos1 ) = $pdf->getAddTextPos();
253 $pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'itemtype'} );
254 $vPos = $vPos - $vPosSpacer;
258 # $x_pos_spine, $y_pos,
259 # ( $x_pos_spine + $spine_width ),
260 # ( $y_pos - $label_height )
263 $y_pos = ( $y_pos - $label_height );
265 #warn "END LOOP Y_POS =$y_pos";
266 # warn "PAGECOUNT END LOOP=$page_break_count";
267 if ( $page_break_count == 8 ) {
269 $pdf->openpage($pagenumber);
271 #warn "############# PAGEBREAK ###########";
272 $page_break_count = 0;
274 $y_pos = ( $y_pos_initial + 90 );
280 #warn "#----------------------------------\n";
287 #------------------------------------------------
289 print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");