9 use HTML::Template::Pro;
11 use PDF::Reuse::Barcode;
18 my $htdocs_path = C4::Context->config('intrahtdocs');
20 print $cgi->header( -type => 'application/pdf', -attachment => 'barcode.pdf' );
24 #warn "label-print-pdf ***";
26 # get the printing settings
27 my $template = GetActiveLabelTemplate();
28 my $conf_data = get_label_options();
29 my $profile = GetAssociatedProfile($template->{'tmpl_id'});
31 my $batch_id = $cgi->param('batch_id');
32 my @resultsloop = get_label_items($batch_id);
36 my $barcodetype = $conf_data->{'barcodetype'};
37 my $printingtype = $conf_data->{'printingtype'};
38 my $guidebox = $conf_data->{'guidebox'};
39 my $start_label = $conf_data->{'startlabel'};
40 if ($cgi->param('startlabel')) {
41 $start_label = $cgi->param('startlabel'); # A bit of a hack to allow setting the starting label from the address bar... -fbcit
43 warn "Starting on label #$start_label" if $DEBUG;
44 my $fontsize = $template->{'fontsize'};
45 my $units = $template->{'units'};
48 warn "fontsize = $fontsize";
49 #warn Dumper $template;
51 my $unitvalue = GetUnitsValue($units);
52 my $prof_unitvalue = GetUnitsValue($profile->{'unit'});
54 warn "Template units: $units which converts to $unitvalue PostScript Points" if $DEBUG;
55 warn "Profile units: $profile->{'unit'} which converts to $prof_unitvalue PostScript Points" if $DEBUG;
57 my $tmpl_code = $template->{'tmpl_code'};
58 my $tmpl_desc = $template->{'tmpl_desc'};
60 my $page_height = ( $template->{'page_height'} * $unitvalue );
61 my $page_width = ( $template->{'page_width'} * $unitvalue );
62 my $label_height = ( $template->{'label_height'} * $unitvalue );
63 my $label_width = ( $template->{'label_width'} * $unitvalue );
64 my $spine_width = ( $template->{'label_width'} * $unitvalue );
65 my $circ_width = ( $template->{'label_width'} * $unitvalue );
66 my $top_margin = ( $template->{'topmargin'} * $unitvalue );
67 my $left_margin = ( $template->{'leftmargin'} * $unitvalue );
68 my $colspace = ( $template->{'colgap'} * $unitvalue );
69 my $rowspace = ( $template->{'rowgap'} * $unitvalue );
71 warn "Converted dimensions are:" if $DEBUG;
72 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;
74 my $label_cols = $template->{'cols'};
75 my $label_rows = $template->{'rows'};
77 my $margin = $top_margin;
78 my $left_text_margin = 3; # FIXME: This value should not be hardcoded
85 # Some peritent notes from PDF::Reuse regarding prFont()...
86 # If a font wasn't found, Helvetica will be set.
87 # These names are always recognized: Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Courier, Courier-Bold,
88 # Courier-Oblique, Courier-BoldOblique, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
89 # They can be abbreviated: TR, TB, TI, TBI, C, CB, CO, CBO, H, HB, HO, HBO
91 my $fontname = $template->{'font'};
92 my $font = prFont( $fontname );
94 my $text_wrap_cols = GetTextWrapCols( $font, $fontsize, $label_width, $left_text_margin );
96 #warn $label_cols, $label_rows;
101 my $upperRightX = $page_width;
102 my $upperRightY = $page_height;
104 prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
106 #warn "STARTROW = $startrow\n";
108 #my $page_break_count = $startrow;
109 my $codetype; # = 'Code39';
112 # drawbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
114 # draw margin box for alignment page
115 drawbox( ($left_margin), ($top_margin), ($page_width-(2*$left_margin)), ($page_height-(2*$top_margin)) ) if $DEBUG_LPT;
117 # Adjustments for image position and creep -fbcit
118 # NOTE: *All* of these factor in to image position and creep. Keep this in mind when makeing adjustments.
119 # Suggested proceedure: Adjust margins until both top and left margins are correct. Then adjust the label
120 # height and width to correct label creep across and down page. Units are PostScript Points (72 per inch).
122 warn "Active profile: " . ($profile->{'prof_id'}?$profile->{'prof_id'}:"None") if $DEBUG;
125 warn "-------------------------INITIAL VALUES-----------------------------";
126 warn "top margin = $top_margin points\n";
127 warn "left margin = $left_margin points\n";
128 warn "label height = $label_height points\n";
129 warn "label width = $label_width points\n";
132 if ( $profile->{'prof_id'} ) {
133 $top_margin = $top_margin + ($profile->{'offset_vert'} * $prof_unitvalue); # controls vertical offset
134 $label_height = $label_height + ($profile->{'creep_vert'} * $prof_unitvalue); # controls vertical creep
135 $left_margin = $left_margin + ($profile->{'offset_horz'} * $prof_unitvalue); # controls horizontal offset
136 $label_width = $label_width + ($profile->{'creep_horz'} * $prof_unitvalue); # controls horizontal creep
139 if ( $DEBUG && $profile->{'prof_id'} ) {
140 warn "-------------------------ADJUSTED VALUES-----------------------------";
141 warn "top margin = $top_margin points\n";
142 warn "left margin = $left_margin points\n";
143 warn "label height = $label_height points\n";
144 warn "label width = $label_width points\n";
146 warn "No profile associated so no adjustment applied.";
150 my ( $i, $i2 ); # loop counters
154 #warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
155 #warn "$label_rows, $label_cols\n";
156 #warn "$label_height, $label_width\n";
157 #warn "$page_height, $page_width\n";
159 my ( $rowcount, $colcount, $x_pos, $y_pos, $rowtemp, $coltemp );
161 if ( $start_label eq 1 ) {
164 $x_pos = $left_margin;
165 $y_pos = ( $page_height - $top_margin - $label_height );
171 $rowcount = ceil( $start_label / $label_cols );
174 #$rowcount = 1 if $@;
176 $colcount = ( $start_label - ( ( $rowcount - 1 ) * $label_cols ) );
178 $x_pos = $left_margin + ( $label_width * ( $colcount - 1 ) ) +
179 ( $colspace * ( $colcount - 1 ) );
181 $y_pos = $page_height - $top_margin - ( $label_height * $rowcount ) -
182 ( $rowspace * ( $rowcount - 1 ) );
184 warn "Start label specified: $start_label Beginning in row $rowcount, column $colcount" if $DEBUG;
185 warn "X position = $x_pos Y position = $y_pos" if $DEBUG;
186 warn "Rowspace = $rowspace Label height = $label_height" if $DEBUG;
189 #warn "ROW COL $rowcount, $colcount";
191 #my $barcodetype; # = 'Code39';
197 foreach $item (@resultsloop) {
198 warn "Label parameters: xpos=$x_pos, ypos=$y_pos, lblwid=$label_width, lblhig=$label_height" if $DEBUG;
199 my $barcode = $item->{'barcode'};
200 if ( $printingtype eq 'BAR' ) {
201 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
202 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $barcode,
206 elsif ( $printingtype eq 'BARBIB' ) {
207 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
209 # reposoitioning barcode up the top of label
210 my $barcode_height = ($label_height / 1.5 ); ## scaling voodoo
211 my $text_height = $label_height / 2;
212 my $barcode_y = $y_pos + ( $label_height / 2.5 ); ## scaling voodoo
214 DrawBarcode( $x_pos, $barcode_y, $barcode_height, $label_width,
215 $barcode, $barcodetype );
216 DrawSpineText( $y_pos, $text_height, $label_width, $font, $fontsize, $x_pos,
217 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
222 elsif ( $printingtype eq 'BIBBAR' ) {
223 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
224 my $barcode_height = $label_height / 2;
225 DrawBarcode( $x_pos, $y_pos, $barcode_height, $label_width, $barcode,
227 DrawSpineText( $y_pos, $label_height, $label_width, $font, $fontsize, $x_pos,
228 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
233 elsif ( $printingtype eq 'ALT' ) {
234 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
235 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $barcode,
238 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
239 DrawSpineText( $y_pos, $label_height, $label_width, $font, $fontsize, $x_pos,
240 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
246 elsif ( $printingtype eq 'BIB' ) {
247 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
248 DrawSpineText( $y_pos, $label_height, $label_width, $font, $fontsize, $x_pos,
249 $left_text_margin, $text_wrap_cols, \$item, \$conf_data, $printingtype );
263 } # end for item loop
271 sub CalcNextLabelPos {
272 if ( $colcount lt $label_cols ) {
275 $x_pos = ( $x_pos + $label_width + $colspace );
280 $x_pos = $left_margin;
281 if ( $rowcount eq $label_rows ) {
285 $y_pos = ( $page_height - $top_margin - $label_height );
291 $y_pos = ( $y_pos - $rowspace - $label_height );