3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
20 =head1 label-print-pdf.pl
22 this script is really divided into 2 differenvt section,
24 the first section creates, and defines the new PDF file the barcodes
25 using PDF::Reuse::Barcode, then saves the file to disk.
27 the second section then opens the pdf file off disk, and places the spline label
28 text in the left-most column of the page. then save the file again.
30 the reason for this goofyness, it that i couldnt find a single perl package that handled both barcodes and decent text placement.
39 use C4::Interface::CGI::Output;
43 use PDF::Reuse::Barcode;
49 my $htdocs_path = C4::Context->config('intrahtdocs');
53 # get the printing settings
54 my $template = GetActiveLabelTemplate();
55 my $conf_data = get_label_options();
56 my @resultsloop = get_label_items();
57 my $barcodetype = $conf_data->{'barcodetype'};
58 my $printingtype = $conf_data->{'printingtype'};
59 my $guidebox = $conf_data->{'guidebox'};
60 my $start_label = $conf_data->{'startlabel'};
61 my $fontsize = $template->{'fontsize'};
62 my $units = $template->{'units'};
65 warn "fontsize = $fontsize";
67 my $unitvalue = GetUnitsValue($units);
71 my $tmpl_code = $template->{'tmpl_code'};
72 my $tmpl_desc = $template->{'tmpl_desc'};
74 my $page_height = ( $template->{'page_height'} * $unitvalue );
75 my $page_width = ( $template->{'page_width'} * $unitvalue );
76 my $label_height = ( $template->{'label_height'} * $unitvalue );
77 my $label_width = ( $template->{'label_width'} * $unitvalue );
78 my $spine_width = ( $template->{'label_width'} * $unitvalue );
79 my $circ_width = ( $template->{'label_width'} * $unitvalue );
80 my $top_margin = ( $template->{'topmargin'} * $unitvalue );
81 my $left_margin = ( $template->{'leftmargin'} * $unitvalue );
82 my $colspace = ( $template->{'colgap'} * $unitvalue );
83 my $rowspace = ( $template->{'rowgap'} * $unitvalue );
85 my $label_cols = $template->{'cols'};
86 my $label_rows = $template->{'rows'};
88 my $text_wrap_cols = GetTextWrapCols( $fontsize, $label_width );
90 warn $label_cols, $label_rows;
95 my $upperRightX = $page_width;
96 my $upperRightY = $page_height;
100 print STDOUT "Content-Type: application/pdf \r\n\r\n";
103 prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
105 # later feature, change the font-type and size?
106 prFont('C'); # Just setting a font
107 prFontSize($fontsize);
109 my $margin = $top_margin;
110 my $left_text_margin = 3;
114 #warn "STARTROW = $startrow\n";
116 #my $page_break_count = $startrow;
117 my $codetype = 'Code39';
120 #drawbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
123 my ( $i, $i2 ); # loop counters
127 warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
128 warn "$label_rows, $label_cols\n";
129 warn "$label_height, $label_width\n";
130 warn "$page_height, $page_width\n";
132 my ( $rowcount, $colcount, $x_pos, $y_pos, $rowtemp, $coltemp );
134 if ( $start_label eq 1 ) {
137 $x_pos = $left_margin;
138 $y_pos = ( $page_height - $top_margin - $label_height );
142 $rowcount = ceil( $start_label / $label_cols );
143 $colcount = ( $start_label - ( ( $rowcount - 1 ) * $label_cols ) );
145 $x_pos = $left_margin + ( $label_width * ( $colcount - 1 ) ) +
146 ( $colspace * ( $colcount - 1 ) );
148 $y_pos = $page_height - $top_margin - ( $label_height * $rowcount ) -
149 ( $rowspace * ( $rowcount - 1 ) );
153 warn "ROW COL $rowcount, $colcount";
155 #my $barcodetype = 'Code39';
157 foreach $item (@resultsloop) {
159 warn "-----------------";
161 drawbox( $x_pos, $y_pos, $label_width, $label_height );
164 if ( $printingtype eq 'spine' || $printingtype eq 'both' ) {
166 drawbox( $x_pos, $y_pos, $label_width, $label_height );
169 DrawSpineText( $y_pos, $label_height, $fontsize, $x_pos,
170 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
174 if ( $printingtype eq 'barcode' || $printingtype eq 'both' ) {
176 drawbox( $x_pos, $y_pos, $label_width, $label_height );
179 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width,
180 $item->{'barcode'}, $barcodetype );
184 } # end for item loop
187 print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");
189 sub CalcNextLabelPos {
190 if ( $colcount lt $label_cols ) {
193 $x_pos = ( $x_pos + $label_width + $colspace );
198 $x_pos = $left_margin;
199 if ( $rowcount eq $label_rows ) {
203 $y_pos = ( $page_height - $top_margin - $label_height );
209 $y_pos = ( $y_pos - $rowspace - $label_height );