9 use HTML::Template::Pro;
11 use PDF::Reuse::Barcode;
19 my $htdocs_path = C4::Context->config('intrahtdocs');
21 print $cgi->header( -type => 'application/pdf', -attachment => 'barcode.pdf' );
25 #warn "label-print-pdf ***";
27 # get the printing settings
28 my $template = GetActiveLabelTemplate();
29 my $conf_data = get_label_options();
30 my $profile = GetAssociatedProfile($template->{'tmpl_id'});
32 my $batch_id = $cgi->param('batch_id');
33 my @resultsloop = get_label_items($batch_id);
37 my $barcodetype = $conf_data->{'barcodetype'};
38 my $printingtype = $conf_data->{'printingtype'};
39 my $guidebox = $conf_data->{'guidebox'};
40 my $start_label = $conf_data->{'startlabel'};
41 if ($cgi->param('startlabel')) {
42 $start_label = $cgi->param('startlabel'); # A bit of a hack to allow setting the starting label from the address bar... -fbcit
44 warn "Starting on label #$start_label" if $DEBUG;
45 my $fontsize = $template->{'fontsize'};
46 my $units = $template->{'units'};
51 ################### defaults for testing
52 my $barcodetype = 'CODE39';
53 my $printingtype = 'BARBIB';
62 #warn "fontsize = $fontsize";
63 #warn Dumper $template;
65 my $unitvalue = GetUnitsValue($units);
67 warn "Template units: $units which converts to $unitvalue PostScript Points" if $DEBUG;
69 my $tmpl_code = $template->{'tmpl_code'};
70 my $tmpl_desc = $template->{'tmpl_desc'};
72 my $page_height = ( $template->{'page_height'} * $unitvalue );
73 my $page_width = ( $template->{'page_width'} * $unitvalue );
74 my $label_height = ( $template->{'label_height'} * $unitvalue );
75 my $label_width = ( $template->{'label_width'} * $unitvalue );
76 my $spine_width = ( $template->{'label_width'} * $unitvalue );
77 my $circ_width = ( $template->{'label_width'} * $unitvalue );
78 my $top_margin = ( $template->{'topmargin'} * $unitvalue );
79 my $left_margin = ( $template->{'leftmargin'} * $unitvalue );
80 my $colspace = ( $template->{'colgap'} * $unitvalue );
81 my $rowspace = ( $template->{'rowgap'} * $unitvalue );
83 warn "Converted dimensions are:" if $DEBUG;
84 warn "pghth=$page_height, pgwth=$page_width, lblhth=$label_height, lblwth=$label_width, spinwth=$spine_width, circwth=$circ_width, tpmar=$top_margin, lmar=$left_margin, colsp=$colspace, rowsp=$rowspace" if $DEBUG;
86 my $label_cols = $template->{'cols'};
87 my $label_rows = $template->{'rows'};
89 my $text_wrap_cols = GetTextWrapCols( $fontsize, $label_width );
92 #warn $label_cols, $label_rows;
97 my $upperRightX = $page_width;
98 my $upperRightY = $page_height;
104 prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
106 # later feature, change the font-type and size?
107 prFont('C'); # Just setting a font
108 prFontSize($fontsize);
110 my $margin = $top_margin;
111 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 );
122 # draw margin box for alignment page
123 drawbox( ($left_margin), ($top_margin), ($page_width-(2*$left_margin)), ($page_height-(2*$top_margin)) ) if $DEBUG_LPT;
125 # Adjustments for image position and creep -fbcit
126 # NOTE: *All* of these factor in to image position and creep. Keep this in mind when makeing adjustments.
127 # Suggested proceedure: Adjust margins until both top and left margins are correct. Then adjust the label
128 # height and width to correct label creep across and down page. Units are PostScript Points (72 per inch).
130 warn "Active profile: $profile->{'prof_id'}" if $DEBUG;
133 warn "-------------------------INITIAL VALUES-----------------------------";
134 warn "top margin = $top_margin points\n";
135 warn "left margin = $left_margin points\n";
136 warn "label height = $label_height points\n";
137 warn "label width = $label_width points\n";
140 $top_margin = $top_margin + $profile->{'offset_vert'}; # controls vertical offset
141 $label_height = $label_height + $profile->{'creep_vert'}; # controls vertical creep
142 $left_margin = $left_margin + $profile->{'offset_horz'}; # controls horizontal offset
143 $label_width = $label_width + $profile->{'creep_horz'}; # controls horizontal creep
146 warn "-------------------------ADJUSTED VALUES-----------------------------";
147 warn "top margin = $top_margin points\n";
148 warn "left margin = $left_margin points\n";
149 warn "label height = $label_height points\n";
150 warn "label width = $label_width points\n";
154 my ( $i, $i2 ); # loop counters
158 #warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
159 #warn "$label_rows, $label_cols\n";
160 #warn "$label_height, $label_width\n";
161 #warn "$page_height, $page_width\n";
163 my ( $rowcount, $colcount, $x_pos, $y_pos, $rowtemp, $coltemp );
165 if ( $start_label eq 1 ) {
168 $x_pos = $left_margin;
169 $y_pos = ( $page_height - $top_margin - $label_height );
175 $rowcount = ceil( $start_label / $label_cols );
178 #$rowcount = 1 if $@;
180 $colcount = ( $start_label - ( ( $rowcount - 1 ) * $label_cols ) );
182 $x_pos = $left_margin + ( $label_width * ( $colcount - 1 ) ) +
183 ( $colspace * ( $colcount - 1 ) );
185 $y_pos = $page_height - $top_margin - ( $label_height * $rowcount ) -
186 ( $rowspace * ( $rowcount - 1 ) );
188 warn "Start label specified: $start_label Beginning in row $rowcount, column $colcount" if $DEBUG;
189 warn "X position = $x_pos Y position = $y_pos" if $DEBUG;
190 warn "Rowspace = $rowspace Label height = $label_height" if $DEBUG;
193 #warn "ROW COL $rowcount, $colcount";
195 #my $barcodetype; # = 'Code39';
201 foreach $item (@resultsloop) {
202 warn "Label parameters: xpos=$x_pos, ypos=$y_pos, lblwid=$label_width, lblhig=$label_height" if $DEBUG;
203 my $barcode = $item->{'barcode'};
204 if ( $printingtype eq 'BAR' ) {
205 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
206 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $barcode,
210 elsif ( $printingtype eq 'BARBIB' ) {
211 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
213 # reposoitioning barcode up the top of label
214 my $barcode_height = ($label_height / 1.5 ); ## scaling voodoo
215 my $text_height = $label_height / 2;
216 my $barcode_y = $y_pos + ( $label_height / 2.5 ); ## scaling voodoo
218 DrawBarcode( $x_pos, $barcode_y, $barcode_height, $label_width,
219 $barcode, $barcodetype );
220 DrawSpineText( $y_pos, $text_height, $fontsize, $x_pos,
221 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
226 elsif ( $printingtype eq 'BIBBAR' ) {
227 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
228 my $barcode_height = $label_height / 2;
229 DrawBarcode( $x_pos, $y_pos, $barcode_height, $label_width, $barcode,
231 DrawSpineText( $y_pos, $label_height, $fontsize, $x_pos,
232 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
237 elsif ( $printingtype eq 'ALT' ) {
238 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
239 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $barcode,
242 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
243 DrawSpineText( $y_pos, $label_height, $fontsize, $x_pos,
244 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
250 elsif ( $printingtype eq 'BIB' ) {
251 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
252 DrawSpineText( $y_pos, $label_height, $fontsize, $x_pos,
253 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
267 } # end for item loop
275 sub CalcNextLabelPos {
276 if ( $colcount lt $label_cols ) {
279 $x_pos = ( $x_pos + $label_width + $colspace );
284 $x_pos = $left_margin;
285 if ( $rowcount eq $label_rows ) {
289 $y_pos = ( $page_height - $top_margin - $label_height );
295 $y_pos = ( $y_pos - $rowspace - $label_height );