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.
42 use PDF::Reuse::Barcode;
48 my $htdocs_path = C4::Context->config('intrahtdocs');
52 # get the printing settings
53 my $template = GetActiveLabelTemplate();
54 my $conf_data = get_label_options();
55 my @resultsloop = get_label_items();
56 my $barcodetype = $conf_data->{'barcodetype'};
57 my $printingtype = $conf_data->{'printingtype'};
58 my $guidebox = $conf_data->{'guidebox'};
59 my $start_label = $conf_data->{'startlabel'};
60 my $fontsize = $template->{'fontsize'};
61 my $units = $template->{'units'};
64 warn "fontsize = $fontsize";
66 my $unitvalue = GetUnitsValue($units);
70 my $tmpl_code = $template->{'tmpl_code'};
71 my $tmpl_desc = $template->{'tmpl_desc'};
73 my $page_height = ( $template->{'page_height'} * $unitvalue );
74 my $page_width = ( $template->{'page_width'} * $unitvalue );
75 my $label_height = ( $template->{'label_height'} * $unitvalue );
76 my $label_width = ( $template->{'label_width'} * $unitvalue );
77 my $spine_width = ( $template->{'label_width'} * $unitvalue );
78 my $circ_width = ( $template->{'label_width'} * $unitvalue );
79 my $top_margin = ( $template->{'topmargin'} * $unitvalue );
80 my $left_margin = ( $template->{'leftmargin'} * $unitvalue );
81 my $colspace = ( $template->{'colgap'} * $unitvalue );
82 my $rowspace = ( $template->{'rowgap'} * $unitvalue );
84 my $label_cols = $template->{'cols'};
85 my $label_rows = $template->{'rows'};
87 my $text_wrap_cols = GetTextWrapCols( $fontsize, $label_width );
89 warn $label_cols, $label_rows;
94 my $upperRightX = $page_width;
95 my $upperRightY = $page_height;
99 print STDOUT "Content-Type: application/pdf \r\n\r\n";
102 prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
104 # later feature, change the font-type and size?
105 prFont('C'); # Just setting a font
106 prFontSize($fontsize);
108 my $margin = $top_margin;
109 my $left_text_margin = 3;
113 #warn "STARTROW = $startrow\n";
115 #my $page_break_count = $startrow;
116 my $codetype = 'Code39';
119 #drawbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
122 my ( $i, $i2 ); # loop counters
126 warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
127 warn "$label_rows, $label_cols\n";
128 warn "$label_height, $label_width\n";
129 warn "$page_height, $page_width\n";
131 my ( $rowcount, $colcount, $x_pos, $y_pos, $rowtemp, $coltemp );
133 if ( $start_label eq 1 ) {
136 $x_pos = $left_margin;
137 $y_pos = ( $page_height - $top_margin - $label_height );
141 $rowcount = ceil( $start_label / $label_cols );
142 $colcount = ( $start_label - ( ( $rowcount - 1 ) * $label_cols ) );
144 $x_pos = $left_margin + ( $label_width * ( $colcount - 1 ) ) +
145 ( $colspace * ( $colcount - 1 ) );
147 $y_pos = $page_height - $top_margin - ( $label_height * $rowcount ) -
148 ( $rowspace * ( $rowcount - 1 ) );
152 warn "ROW COL $rowcount, $colcount";
154 #my $barcodetype = 'Code39';
156 foreach $item (@resultsloop) {
158 warn "-----------------";
160 drawbox( $x_pos, $y_pos, $label_width, $label_height );
163 if ( $printingtype eq 'spine' || $printingtype eq 'both' ) {
165 drawbox( $x_pos, $y_pos, $label_width, $label_height );
168 DrawSpineText( $y_pos, $label_height, $fontsize, $x_pos,
169 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
173 if ( $printingtype eq 'barcode' || $printingtype eq 'both' ) {
175 drawbox( $x_pos, $y_pos, $label_width, $label_height );
178 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width,
179 $item->{'barcode'}, $barcodetype );
183 } # end for item loop
186 print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");
188 sub CalcNextLabelPos {
189 if ( $colcount lt $label_cols ) {
192 $x_pos = ( $x_pos + $label_width + $colspace );
197 $x_pos = $left_margin;
198 if ( $rowcount eq $label_rows ) {
202 $y_pos = ( $page_height - $top_margin - $label_height );
208 $y_pos = ( $y_pos - $rowspace - $label_height );