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 $units = $template->{'units'};
47 #warn "fontsize = $fontsize";
48 #warn Dumper $template;
50 my $unitvalue = GetUnitsValue($units);
51 my $prof_unitvalue = GetUnitsValue($profile->{'unit'});
53 warn "Template units: $units which converts to $unitvalue PostScript Points" if $DEBUG;
54 warn "Profile units: $profile->{'unit'} which converts to $prof_unitvalue PostScript Points" if $DEBUG;
56 my $tmpl_code = $template->{'tmpl_code'};
57 my $tmpl_desc = $template->{'tmpl_desc'};
59 my $page_height = ( $template->{'page_height'} * $unitvalue );
60 my $page_width = ( $template->{'page_width'} * $unitvalue );
61 my $label_height = ( $template->{'label_height'} * $unitvalue );
62 my $label_width = ( $template->{'label_width'} * $unitvalue );
63 my $spine_width = ( $template->{'label_width'} * $unitvalue );
64 my $circ_width = ( $template->{'label_width'} * $unitvalue );
65 my $top_margin = ( $template->{'topmargin'} * $unitvalue );
66 my $left_margin = ( $template->{'leftmargin'} * $unitvalue );
67 my $colspace = ( $template->{'colgap'} * $unitvalue );
68 my $rowspace = ( $template->{'rowgap'} * $unitvalue );
70 warn "Converted dimensions are:" if $DEBUG;
71 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;
73 my $label_cols = $template->{'cols'};
74 my $label_rows = $template->{'rows'};
76 my $margin = $top_margin;
77 my $left_text_margin = 3; # FIXME: This value should not be hardcoded
84 # Some peritent notes from PDF::Reuse regarding prFont()...
85 # If a font wasn't found, Helvetica will be set.
86 # These names are always recognized: Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Courier, Courier-Bold,
87 # Courier-Oblique, Courier-BoldOblique, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
88 # They can be abbreviated: TR, TB, TI, TBI, C, CB, CO, CBO, H, HB, HO, HBO
90 my $fontsize = $template->{'fontsize'};
91 my $fontname = $template->{'font'};
93 my $text_wrap_cols = GetTextWrapCols( $fontname, $fontsize, $label_width, $left_text_margin );
95 #warn $label_cols, $label_rows;
100 my $upperRightX = $page_width;
101 my $upperRightY = $page_height;
103 prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
105 #warn "STARTROW = $startrow\n";
107 #my $page_break_count = $startrow;
108 my $codetype; # = 'Code39';
111 # drawbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
113 # draw margin box for alignment page
114 drawbox( ($left_margin), ($top_margin), ($page_width-(2*$left_margin)), ($page_height-(2*$top_margin)) ) if $DEBUG_LPT;
116 # Adjustments for image position and creep -fbcit
117 # NOTE: *All* of these factor in to image position and creep. Keep this in mind when makeing adjustments.
118 # Suggested proceedure: Adjust margins until both top and left margins are correct. Then adjust the label
119 # height and width to correct label creep across and down page. Units are PostScript Points (72 per inch).
121 warn "Active profile: " . ($profile->{'prof_id'}?$profile->{'prof_id'}:"None") if $DEBUG;
124 warn "-------------------------INITIAL VALUES-----------------------------";
125 warn "top margin = $top_margin points\n";
126 warn "left margin = $left_margin points\n";
127 warn "label height = $label_height points\n";
128 warn "label width = $label_width points\n";
131 if ( $profile->{'prof_id'} ) {
132 $top_margin = $top_margin + ($profile->{'offset_vert'} * $prof_unitvalue); # controls vertical offset
133 $label_height = $label_height + ($profile->{'creep_vert'} * $prof_unitvalue); # controls vertical creep
134 $left_margin = $left_margin + ($profile->{'offset_horz'} * $prof_unitvalue); # controls horizontal offset
135 $label_width = $label_width + ($profile->{'creep_horz'} * $prof_unitvalue); # controls horizontal creep
138 if ( $DEBUG && $profile->{'prof_id'} ) {
139 warn "-------------------------ADJUSTED VALUES-----------------------------";
140 warn "top margin = $top_margin points\n";
141 warn "left margin = $left_margin points\n";
142 warn "label height = $label_height points\n";
143 warn "label width = $label_width points\n";
145 warn "No profile associated so no adjustment applied.";
149 my ( $i, $i2 ); # loop counters
153 #warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
154 #warn "$label_rows, $label_cols\n";
155 #warn "$label_height, $label_width\n";
156 #warn "$page_height, $page_width\n";
158 my ( $rowcount, $colcount, $x_pos, $y_pos, $rowtemp, $coltemp );
160 if ( $start_label eq 1 ) {
163 $x_pos = $left_margin;
164 $y_pos = ( $page_height - $top_margin - $label_height );
170 $rowcount = ceil( $start_label / $label_cols );
173 #$rowcount = 1 if $@;
175 $colcount = ( $start_label - ( ( $rowcount - 1 ) * $label_cols ) );
177 $x_pos = $left_margin + ( $label_width * ( $colcount - 1 ) ) +
178 ( $colspace * ( $colcount - 1 ) );
180 $y_pos = $page_height - $top_margin - ( $label_height * $rowcount ) -
181 ( $rowspace * ( $rowcount - 1 ) );
183 warn "Start label specified: $start_label Beginning in row $rowcount, column $colcount" if $DEBUG;
184 warn "X position = $x_pos Y position = $y_pos" if $DEBUG;
185 warn "Rowspace = $rowspace Label height = $label_height" if $DEBUG;
188 #warn "ROW COL $rowcount, $colcount";
190 #my $barcodetype; # = 'Code39';
196 foreach $item (@resultsloop) {
197 warn "Label parameters: xpos=$x_pos, ypos=$y_pos, lblwid=$label_width, lblhig=$label_height" if $DEBUG;
198 my $barcode = $item->{'barcode'};
199 if ( $printingtype eq 'BAR' ) {
200 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
201 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $barcode,
205 elsif ( $printingtype eq 'BARBIB' ) {
206 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
208 # reposoitioning barcode up the top of label
209 my $barcode_height = ($label_height / 1.5 ); ## scaling voodoo
210 my $text_height = $label_height / 2;
211 my $barcode_y = $y_pos + ( $label_height / 2.5 ); ## scaling voodoo
213 DrawBarcode( $x_pos, $barcode_y, $barcode_height, $label_width,
214 $barcode, $barcodetype );
215 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
216 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
221 elsif ( $printingtype eq 'BIBBAR' ) {
222 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
223 my $barcode_height = $label_height / 2;
224 DrawBarcode( $x_pos, $y_pos, $barcode_height, $label_width, $barcode,
226 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
227 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
232 elsif ( $printingtype eq 'ALT' ) {
233 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
234 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $barcode,
237 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
238 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
239 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
245 elsif ( $printingtype eq 'BIB' ) {
246 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
247 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
248 $left_text_margin, $text_wrap_cols, \$item, \$conf_data, $printingtype );
262 } # end for item loop
270 sub CalcNextLabelPos {
271 if ( $colcount lt $label_cols ) {
274 $x_pos = ( $x_pos + $label_width + $colspace );
279 $x_pos = $left_margin;
280 if ( $rowcount eq $label_rows ) {
284 $y_pos = ( $page_height - $top_margin - $label_height );
290 $y_pos = ( $y_pos - $rowspace - $label_height );