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 $barcodetype = $conf_data->{'barcodetype'};
40 my $printingtype = $conf_data->{'printingtype'};
41 my $guidebox = $conf_data->{'guidebox'};
42 my $start_label = $conf_data->{'startlabel'};
43 if ($cgi->param('startlabel')) {
44 $start_label = $cgi->param('startlabel'); # A bit of a hack to allow setting the starting label from the address bar... -fbcit
46 warn "Starting on label #$start_label" if $DEBUG;
47 my $units = $template->{'units'};
49 if ($printingtype eq 'PATCRD') {
50 @resultsloop = GetPatronCardItems($batch_id);
52 @resultsloop = get_label_items($batch_id);
56 #warn "fontsize = $fontsize";
57 #warn Dumper $template;
59 my $unitvalue = GetUnitsValue($units);
60 my $prof_unitvalue = GetUnitsValue($profile->{'unit'});
62 warn "Template units: $units which converts to $unitvalue PostScript Points" if $DEBUG;
63 warn "Profile units: $profile->{'unit'} which converts to $prof_unitvalue PostScript Points" if $DEBUG;
65 my $tmpl_code = $template->{'tmpl_code'};
66 my $tmpl_desc = $template->{'tmpl_desc'};
68 my $page_height = ( $template->{'page_height'} * $unitvalue );
69 my $page_width = ( $template->{'page_width'} * $unitvalue );
70 my $label_height = ( $template->{'label_height'} * $unitvalue );
71 my $label_width = ( $template->{'label_width'} * $unitvalue );
72 my $spine_width = ( $template->{'label_width'} * $unitvalue );
73 my $circ_width = ( $template->{'label_width'} * $unitvalue );
74 my $top_margin = ( $template->{'topmargin'} * $unitvalue );
75 my $left_margin = ( $template->{'leftmargin'} * $unitvalue );
76 my $colspace = ( $template->{'colgap'} * $unitvalue );
77 my $rowspace = ( $template->{'rowgap'} * $unitvalue );
79 warn "Converted dimensions are:" if $DEBUG;
80 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;
82 my $label_cols = $template->{'cols'};
83 my $label_rows = $template->{'rows'};
85 my $margin = $top_margin;
86 my $left_text_margin = 3; # FIXME: This value should not be hardcoded
93 # Some peritent notes from PDF::Reuse regarding prFont()...
94 # If a font wasn't found, Helvetica will be set.
95 # These names are always recognized: Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Courier, Courier-Bold,
96 # Courier-Oblique, Courier-BoldOblique, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
97 # They can be abbreviated: TR, TB, TI, TBI, C, CB, CO, CBO, H, HB, HO, HBO
99 my $fontsize = $template->{'fontsize'};
100 my $fontname = $template->{'font'};
102 my $text_wrap_cols = GetTextWrapCols( $fontname, $fontsize, $label_width, $left_text_margin );
104 #warn $label_cols, $label_rows;
109 my $upperRightX = $page_width;
110 my $upperRightY = $page_height;
112 prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
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'}?$profile->{'prof_id'}:"None") 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 if ( $profile->{'prof_id'} ) {
141 $top_margin = $top_margin + ($profile->{'offset_vert'} * $prof_unitvalue); # controls vertical offset
142 $label_height = $label_height + ($profile->{'creep_vert'} * $prof_unitvalue); # controls vertical creep
143 $left_margin = $left_margin + ($profile->{'offset_horz'} * $prof_unitvalue); # controls horizontal offset
144 $label_width = $label_width + ($profile->{'creep_horz'} * $prof_unitvalue); # controls horizontal creep
147 if ( $DEBUG && $profile->{'prof_id'} ) {
148 warn "-------------------------ADJUSTED VALUES-----------------------------";
149 warn "top margin = $top_margin points\n";
150 warn "left margin = $left_margin points\n";
151 warn "label height = $label_height points\n";
152 warn "label width = $label_width points\n";
154 warn "No profile associated so no adjustment applied.";
158 my ( $i, $i2 ); # loop counters
162 #warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
163 #warn "$label_rows, $label_cols\n";
164 #warn "$label_height, $label_width\n";
165 #warn "$page_height, $page_width\n";
167 my ( $rowcount, $colcount, $x_pos, $y_pos, $rowtemp, $coltemp );
169 if ( $start_label eq 1 ) {
172 $x_pos = $left_margin;
173 $y_pos = ( $page_height - $top_margin - $label_height );
179 $rowcount = ceil( $start_label / $label_cols );
182 #$rowcount = 1 if $@;
184 $colcount = ( $start_label - ( ( $rowcount - 1 ) * $label_cols ) );
186 $x_pos = $left_margin + ( $label_width * ( $colcount - 1 ) ) +
187 ( $colspace * ( $colcount - 1 ) );
189 $y_pos = $page_height - $top_margin - ( $label_height * $rowcount ) -
190 ( $rowspace * ( $rowcount - 1 ) );
192 warn "Start label specified: $start_label Beginning in row $rowcount, column $colcount" if $DEBUG;
193 warn "X position = $x_pos Y position = $y_pos" if $DEBUG;
194 warn "Rowspace = $rowspace Label height = $label_height" if $DEBUG;
197 #warn "ROW COL $rowcount, $colcount";
199 #my $barcodetype; # = 'Code39';
205 foreach $item (@resultsloop) {
206 warn "Label parameters: xpos=$x_pos, ypos=$y_pos, lblwid=$label_width, lblhig=$label_height" if $DEBUG;
207 if ( $printingtype eq 'BAR' ) {
208 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
209 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $item->{'barcode'},
213 elsif ( $printingtype eq 'BARBIB' ) {
214 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
216 # reposoitioning barcode up the top of label
217 my $barcode_height = ($label_height / 1.5 ); ## scaling voodoo
218 my $text_height = $label_height / 2;
219 my $barcode_y = $y_pos + ( $label_height / 2.5 ); ## scaling voodoo
221 DrawBarcode( $x_pos, $barcode_y, $barcode_height, $label_width,
222 $item->{'barcode'}, $barcodetype );
223 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
224 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
229 elsif ( $printingtype eq 'BIBBAR' ) {
230 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
231 my $barcode_height = $label_height / 2;
232 DrawBarcode( $x_pos, $y_pos, $barcode_height, $label_width, $item->{'barcode'},
234 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
235 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
240 elsif ( $printingtype eq 'ALT' ) {
241 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
242 DrawBarcode( $x_pos, $y_pos, $label_height, $label_width, $item->{'barcode'},
245 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
246 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
247 $left_text_margin, $text_wrap_cols, \$item, \$conf_data );
253 elsif ( $printingtype eq 'BIB' ) {
254 drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
255 DrawSpineText( $x_pos, $y_pos, $label_height, $label_width, $fontname, $fontsize,
256 $left_text_margin, $text_wrap_cols, \$item, \$conf_data, $printingtype );
260 elsif ( $printingtype eq 'PATCRD' ) {
261 my $borrowernumber = '3'; # Hardcoded for testing purposes...
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 );