11 use HTML::Template::Pro;
13 use PDF::Reuse::Barcode;
21 my $htdocs_path = C4::Context->config('intrahtdocs');
23 print $cgi->header( -type => 'application/pdf', -attachment => 'barcode.pdf' );
27 #warn "label-print-pdf ***";
29 # get the printing settings
30 my $template = GetActiveLabelTemplate();
31 my $conf_data = get_label_options();
32 my $profile = GetAssociatedProfile($template->{'tmpl_id'});
34 my $batch_id = $cgi->param('batch_id');
39 my $batch_type = $conf_data->{'type'};
40 my $barcodetype = $conf_data->{'barcodetype'};
41 my $printingtype = $conf_data->{'printingtype'};
42 my $guidebox = $conf_data->{'guidebox'};
43 my $start_label = $conf_data->{'startlabel'};
44 if ($cgi->param('startlabel')) {
45 $start_label = $cgi->param('startlabel'); # A bit of a hack to allow setting the starting label from the address bar... -fbcit
47 warn "Starting on label #$start_label" if $DEBUG;
48 my $units = $template->{'units'};
50 if ($printingtype eq 'PATCRD') {
51 @resultsloop = GetPatronCardItems($batch_id);
53 @resultsloop = GetLabelItems($batch_id);
57 #warn "fontsize = $fontsize";
58 #warn Dumper $template;
60 my $unitvalue = GetUnitsValue($units);
61 my $prof_unitvalue = GetUnitsValue($profile->{'unit'});
63 warn "Template units: $units which converts to $unitvalue PostScript Points" if $DEBUG;
64 warn "Profile units: $profile->{'unit'} which converts to $prof_unitvalue PostScript Points" if $DEBUG;
66 my $tmpl_code = $template->{'tmpl_code'};
67 my $tmpl_desc = $template->{'tmpl_desc'};
69 my $page_height = ( $template->{'page_height'} * $unitvalue );
70 my $page_width = ( $template->{'page_width'} * $unitvalue );
71 my $label_height = ( $template->{'label_height'} * $unitvalue );
72 my $label_width = ( $template->{'label_width'} * $unitvalue );
73 my $spine_width = ( $template->{'label_width'} * $unitvalue );
74 my $circ_width = ( $template->{'label_width'} * $unitvalue );
75 my $top_margin = ( $template->{'topmargin'} * $unitvalue );
76 my $left_margin = ( $template->{'leftmargin'} * $unitvalue );
77 my $colspace = ( $template->{'colgap'} * $unitvalue );
78 my $rowspace = ( $template->{'rowgap'} * $unitvalue );
80 warn "Converted dimensions are:" if $DEBUG;
81 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;
83 my $label_cols = $template->{'cols'};
84 my $label_rows = $template->{'rows'};
86 my $margin = $top_margin;
87 my $left_text_margin = 3; # FIXME: This value should not be hardcoded
94 # Some peritent notes from PDF::Reuse regarding prFont()...
95 # If a font wasn't found, Helvetica will be set.
96 # These names are always recognized: Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Courier, Courier-Bold,
97 # Courier-Oblique, Courier-BoldOblique, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
98 # They can be abbreviated: TR, TB, TI, TBI, C, CB, CO, CBO, H, HB, HO, HBO
100 my $fontsize = $template->{'fontsize'};
101 my $fontname = $template->{'font'};
103 my $text_wrap_cols = GetTextWrapCols( $fontname, $fontsize, $label_width, $left_text_margin );
105 #warn $label_cols, $label_rows;
110 my $upperRightX = $page_width;
111 my $upperRightY = $page_height;
113 prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
115 #warn "STARTROW = $startrow\n";
117 #my $page_break_count = $startrow;
118 my $codetype; # = 'Code39';
121 # drawbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
123 # draw margin box for alignment page
124 drawbox( ($left_margin), ($top_margin), ($page_width-(2*$left_margin)), ($page_height-(2*$top_margin)) ) if $DEBUG_LPT;
126 # Adjustments for image position and creep -fbcit
127 # NOTE: *All* of these factor in to image position and creep. Keep this in mind when makeing adjustments.
128 # Suggested proceedure: Adjust margins until both top and left margins are correct. Then adjust the label
129 # height and width to correct label creep across and down page. Units are PostScript Points (72 per inch).
131 warn "Active profile: " . ($profile->{'prof_id'}?$profile->{'prof_id'}:"None") if $DEBUG;
134 warn "-------------------------INITIAL VALUES-----------------------------";
135 warn "top margin = $top_margin points\n";
136 warn "left margin = $left_margin points\n";
137 warn "label height = $label_height points\n";
138 warn "label width = $label_width points\n";
141 if ( $profile->{'prof_id'} ) {
142 $top_margin = $top_margin + ($profile->{'offset_vert'} * $prof_unitvalue); # controls vertical offset
143 $label_height = $label_height + ($profile->{'creep_vert'} * $prof_unitvalue); # controls vertical creep
144 $left_margin = $left_margin + ($profile->{'offset_horz'} * $prof_unitvalue); # controls horizontal offset
145 $label_width = $label_width + ($profile->{'creep_horz'} * $prof_unitvalue); # controls horizontal creep
148 if ( $DEBUG && $profile->{'prof_id'} ) {
149 warn "-------------------------ADJUSTED VALUES-----------------------------";
150 warn "top margin = $top_margin points\n";
151 warn "left margin = $left_margin points\n";
152 warn "label height = $label_height points\n";
153 warn "label width = $label_width points\n";
155 warn "No profile associated so no adjustment applied.";
159 my ( $i, $i2 ); # loop counters
163 #warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
164 #warn "$label_rows, $label_cols\n";
165 #warn "$label_height, $label_width\n";
166 #warn "$page_height, $page_width\n";
168 my ( $rowcount, $colcount, $x_pos, $y_pos, $rowtemp, $coltemp );
170 if ( $start_label eq 1 ) {
173 $x_pos = $left_margin;
174 $y_pos = ( $page_height - $top_margin - $label_height );
180 $rowcount = ceil( $start_label / $label_cols );
183 #$rowcount = 1 if $@;
185 $colcount = ( $start_label - ( ( $rowcount - 1 ) * $label_cols ) );
187 $x_pos = $left_margin + ( $label_width * ( $colcount - 1 ) ) +
188 ( $colspace * ( $colcount - 1 ) );
190 $y_pos = $page_height - $top_margin - ( $label_height * $rowcount ) -
191 ( $rowspace * ( $rowcount - 1 ) );
193 warn "Start label specified: $start_label Beginning in row $rowcount, column $colcount" if $DEBUG;
194 warn "X position = $x_pos Y position = $y_pos" if $DEBUG;
195 warn "Rowspace = $rowspace Label height = $label_height" if $DEBUG;
198 #warn "ROW COL $rowcount, $colcount";
200 #my $barcodetype; # = 'Code39';
206 foreach $item (@resultsloop) {
207 warn "Label parameters: xpos=$x_pos, ypos=$y_pos, lblwid=$label_width, lblhig=$label_height" if $DEBUG;
208 if ( $printingtype eq 'BAR' ) {
209 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
210 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $item->{'barcode'},
214 elsif ( $printingtype eq 'BARBIB' ) {
215 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
217 # reposoitioning barcode up the top of label
218 my $barcode_height = ($label_height / 1.5 ); ## scaling voodoo
219 my $text_height = $label_height / 2;
220 my $barcode_y = $y_pos + ( $label_height / 2.5 ); ## scaling voodoo
222 DrawBarcode( $x_pos, $barcode_y, $barcode_height, $label_width,
223 $item->{'barcode'}, $barcodetype );
224 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
225 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
230 elsif ( $printingtype eq 'BIBBAR' ) {
231 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
232 my $barcode_height = $label_height / 2;
233 DrawBarcode( $x_pos, $y_pos, $barcode_height, $label_width, $item->{'barcode'},
235 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
236 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
241 elsif ( $printingtype eq 'ALT' ) {
242 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
243 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $item->{'barcode'},
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 );
254 elsif ( $printingtype eq 'BIB' ) {
255 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
256 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
257 $left_text_margin, $text_wrap_cols, \$item, \$conf_data, $printingtype );
261 elsif ( $printingtype eq 'PATCRD' ) {
262 my $patron_data = $item;
264 #FIXME: This needs to be paramatized and passed in from the user...
265 #Each element of this hash is a separate line on the patron card. Keys are the text to print and the associated data is the point size.
267 $patron_data->{'description'} => $fontsize,
268 $patron_data->{'branchname'} => ($fontsize + 3),
271 warn "Generating patron card for cardnumber $patron_data->{'cardnumber'}";
273 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
274 my $barcode_height = $label_height / 2.75; #FIXME: Scaling barcode height; this needs to be a user parameter.
275 DrawBarcode( $x_pos, $y_pos, $barcode_height, $label_width, $patron_data->{'cardnumber'},
277 DrawPatronCardText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
278 $left_text_margin, $text_wrap_cols, $text, $printingtype );
292 } # end for item loop
300 sub CalcNextLabelPos {
301 if ( $colcount lt $label_cols ) {
304 $x_pos = ( $x_pos + $label_width + $colspace );
309 $x_pos = $left_margin;
310 if ( $rowcount eq $label_rows ) {
314 $y_pos = ( $page_height - $top_margin - $label_height );
320 $y_pos = ( $y_pos - $rowspace - $label_height );