9 use HTML
::Template
::Pro
;
11 use PDF
::Reuse
::Barcode
;
16 my $htdocs_path = C4
::Context
->config('intrahtdocs');
18 print $cgi->header( -type
=> 'application/pdf', -attachment
=> 'barcode.pdf' );
22 #warn "label-print-pdf ***";
24 # get the printing settings
25 my $template = GetActiveLabelTemplate
();
26 my $conf_data = get_label_options
();
28 my $batch_id = $cgi->param('batch_id');
29 my @resultsloop = get_label_items
($batch_id);
33 my $barcodetype = $conf_data->{'barcodetype'};
34 my $printingtype = $conf_data->{'printingtype'};
35 my $guidebox = $conf_data->{'guidebox'};
36 my $start_label = $conf_data->{'startlabel'};
37 my $fontsize = $template->{'fontsize'};
38 my $units = $template->{'units'};
43 ################### defaults for testing
44 my $barcodetype = 'CODE39';
45 my $printingtype = 'BARBIB';
54 #warn "fontsize = $fontsize";
55 #warn Dumper $template;
57 my $unitvalue = GetUnitsValue
($units);
59 my $tmpl_code = $template->{'tmpl_code'};
60 my $tmpl_desc = $template->{'tmpl_desc'};
62 my $page_height = ( $template->{'page_height'} * $unitvalue );
63 my $page_width = ( $template->{'page_width'} * $unitvalue );
64 my $label_height = ( $template->{'label_height'} * $unitvalue );
65 my $label_width = ( $template->{'label_width'} * $unitvalue );
66 my $spine_width = ( $template->{'label_width'} * $unitvalue );
67 my $circ_width = ( $template->{'label_width'} * $unitvalue );
68 my $top_margin = ( $template->{'topmargin'} * $unitvalue );
69 my $left_margin = ( $template->{'leftmargin'} * $unitvalue );
70 my $colspace = ( $template->{'colgap'} * $unitvalue );
71 my $rowspace = ( $template->{'rowgap'} * $unitvalue );
73 my $label_cols = $template->{'cols'};
74 my $label_rows = $template->{'rows'};
76 my $text_wrap_cols = GetTextWrapCols
( $fontsize, $label_width );
78 #warn $label_cols, $label_rows;
83 my $upperRightX = $page_width;
84 my $upperRightY = $page_height;
90 prMbox
( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
92 # later feature, change the font-type and size?
93 prFont
('C'); # Just setting a font
94 prFontSize
($fontsize);
96 my $margin = $top_margin;
97 my $left_text_margin = 3;
100 #warn "STARTROW = $startrow\n";
102 #my $page_break_count = $startrow;
103 my $codetype; # = 'Code39';
106 #drawbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
109 my ( $i, $i2 ); # loop counters
113 #warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
114 #warn "$label_rows, $label_cols\n";
115 #warn "$label_height, $label_width\n";
116 #warn "$page_height, $page_width\n";
118 my ( $rowcount, $colcount, $x_pos, $y_pos, $rowtemp, $coltemp );
120 if ( $start_label eq 1 ) {
123 $x_pos = $left_margin;
124 $y_pos = ( $page_height - $top_margin - $label_height );
130 $rowcount = ceil
( $start_label / $label_cols );
133 #$rowcount = 1 if $@;
135 $colcount = ( $start_label - ( ( $rowcount - 1 ) * $label_cols ) );
137 $x_pos = $left_margin + ( $label_width * ( $colcount - 1 ) ) +
138 ( $colspace * ( $colcount - 1 ) );
140 $y_pos = $page_height - $top_margin - ( $label_height * $rowcount ) -
141 ( $rowspace * ( $rowcount - 1 ) );
145 #warn "ROW COL $rowcount, $colcount";
147 #my $barcodetype; # = 'Code39';
153 foreach $item (@resultsloop) {
154 # warn "$x_pos, $y_pos, $label_width, $label_height";
155 my $barcode = $item->{'barcode'};
156 if ( $printingtype eq 'BAR' ) {
157 drawbox
( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
158 DrawBarcode
( $x_pos, $y_pos, $label_height, $label_width, $barcode,
162 elsif ( $printingtype eq 'BARBIB' ) {
163 drawbox
( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
165 # reposoitioning barcode up the top of label
166 my $barcode_height = ($label_height / 1.5 ); ## scaling voodoo
167 my $text_height = $label_height / 2;
168 my $barcode_y = $y_pos + ( $label_height / 2.5 ); ## scaling voodoo
170 DrawBarcode
( $x_pos, $barcode_y, $barcode_height, $label_width,
171 $barcode, $barcodetype );
172 DrawSpineText
( $y_pos, $text_height, $fontsize, $x_pos,
173 $left_text_margin, $text_wrap_cols, \
$item, \
$conf_data );
178 elsif ( $printingtype eq 'BIBBAR' ) {
179 drawbox
( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
180 my $barcode_height = $label_height / 2;
181 DrawBarcode
( $x_pos, $y_pos, $barcode_height, $label_width, $barcode,
183 DrawSpineText
( $y_pos, $label_height, $fontsize, $x_pos,
184 $left_text_margin, $text_wrap_cols, \
$item, \
$conf_data );
189 elsif ( $printingtype eq 'ALT' ) {
190 drawbox
( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
191 DrawBarcode
( $x_pos, $y_pos, $label_height, $label_width, $barcode,
194 drawbox
( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
195 DrawSpineText
( $y_pos, $label_height, $fontsize, $x_pos,
196 $left_text_margin, $text_wrap_cols, \
$item, \
$conf_data );
202 elsif ( $printingtype eq 'BIB' ) {
203 drawbox
( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;
204 DrawSpineText
( $y_pos, $label_height, $fontsize, $x_pos,
205 $left_text_margin, $text_wrap_cols, \
$item, \
$conf_data );
219 } # end for item loop
227 sub CalcNextLabelPos
{
228 if ( $colcount lt $label_cols ) {
231 $x_pos = ( $x_pos + $label_width + $colspace );
236 $x_pos = $left_margin;
237 if ( $rowcount eq $label_rows ) {
241 $y_pos = ( $page_height - $top_margin - $label_height );
247 $y_pos = ( $y_pos - $rowspace - $label_height );