Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 234 lines (194 sloc) 12.16 kb
a0b06fb @ctfliblime Prepare for perlbrew usage by changing all script magic to "#!/usr/bi…
ctfliblime authored
1 #!/usr/bin/env perl
64260d4 Inital add of spine label perl files.
sushi authored
2
2ffd5b7 rel_3_0 moved to HEAD
tipaul authored
3 use strict;
4d4e96d bug 2505: enable warnings for labels/label-print-pdf.pl
Galen Charlton authored
4 use warnings;
5
64260d4 Inital add of spine label perl files.
sushi authored
6 use CGI;
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
7
8 use C4::Debug;
9 use C4::Labels::Batch 1.000000;
10 use C4::Labels::Template 1.000000;
11 use C4::Labels::Layout 1.000000;
12 use C4::Labels::PDF 1.000000;
13 use C4::Labels::Label 1.000000;
14
15 my $cgi = new CGI;
16
39d227d [24/40] Adding single/multiple label printing to label export code an…
Chris Nighswonger authored
17 my $batch_id = $cgi->param('batch_id') if $cgi->param('batch_id');
18 my $template_id = $cgi->param('template_id') || undef;
19 my $layout_id = $cgi->param('layout_id') || undef;
20 my $start_label = $cgi->param('start_label') || 1;
21 my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
22 my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
23
24 my $items = undef;
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
25
39d227d [24/40] Adding single/multiple label printing to label export code an…
Chris Nighswonger authored
26 my $pdf_file = (@label_ids || @item_numbers ? "label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
771af46 @hgq [fixes #12917357] repurpose callnum_split as split format type.
hgq authored
27 print $cgi->header( -type => 'application/pdf', #'text/plain',
39d227d [24/40] Adding single/multiple label printing to label export code an…
Chris Nighswonger authored
28 -encoding => 'utf-8',
771af46 @hgq [fixes #12917357] repurpose callnum_split as split format type.
hgq authored
29 -attachment => "$pdf_file.pdf", #"$pdf_file.txt",
39d227d [24/40] Adding single/multiple label printing to label export code an…
Chris Nighswonger authored
30 );
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
31
32 my $pdf = C4::Labels::PDF->new(InitVars => 0);
33 my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
34 my $template = C4::Labels::Template->retrieve(template_id => $template_id, profile_id => 1);
35 my $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
36
37 sub _calc_next_label_pos {
38 my ($row_count, $col_count, $llx, $lly) = @_;
39 if ($col_count lt $template->get_attr('cols')) {
40 $llx = ($llx + $template->get_attr('label_width') + $template->get_attr('col_gap'));
41 $col_count++;
42 }
43 else {
44 $llx = $template->get_attr('left_margin');
45 if ($row_count eq $template->get_attr('rows')) {
46 $pdf->Page();
47 $lly = ($template->get_attr('page_height') - $template->get_attr('top_margin') - $template->get_attr('label_height'));
48 $row_count = 1;
49 }
50 else {
51 $lly = ($lly - $template->get_attr('row_gap') - $template->get_attr('label_height'));
52 $row_count++;
53 }
54 $col_count = 1;
55 }
56 return ($row_count, $col_count, $llx, $lly);
e37f8c2 Labels Cleanup (Part 2 of Many)
Joe Atzberger authored
57 }
64260d4 Inital add of spine label perl files.
sushi authored
58
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
59 my $fs = $layout->get_attr('format_string');
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
60 $| = 1;
64260d4 Inital add of spine label perl files.
sushi authored
61
2ffd5b7 rel_3_0 moved to HEAD
tipaul authored
62 # set the paper size
63 my $lowerLeftX = 0;
64 my $lowerLeftY = 0;
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
65 my $upperRightX = $template->get_attr('page_width');
66 my $upperRightY = $template->get_attr('page_height');
67
68 $pdf->Compress(1);
69 $pdf->Mbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
70
71 my ($row_count, $col_count, $llx, $lly) = $template->get_label_position($start_label);
39d227d [24/40] Adding single/multiple label printing to label export code an…
Chris Nighswonger authored
72
73 if (@label_ids) {
74 my $batch_items = $batch->get_attr('items');
75 grep {
76 my $label_id = $_;
77 push(@{$items}, grep{$_->{'label_id'} == $label_id;} @{$batch_items});
78 } @label_ids;
79 }
80 elsif (@item_numbers) {
81 grep {
82 push(@{$items}, {item_number => $_});
83 } @item_numbers;
84 }
85 else {
86 $items = $batch->get_attr('items');
87 }
88
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
89 LABEL_ITEMS:
39d227d [24/40] Adding single/multiple label printing to label export code an…
Chris Nighswonger authored
90 foreach my $item (@{$items}) {
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
91 my ($barcode_llx, $barcode_lly, $barcode_width, $barcode_y_scale_factor) = 0,0,0,0;
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
92 if ($layout->get_attr('printing_type') eq 'ALT') { # we process the ALT style printing type here because it is not an atomic printing type
93 my $label_a = C4::Labels::Label->new(
94 batch_id => $batch_id,
95 item_number => $item->{'item_number'},
96 llx => $llx,
97 lly => $lly,
98 width => $template->get_attr('label_width'),
99 height => $template->get_attr('label_height'),
100 top_text_margin => $template->get_attr('top_text_margin'),
101 left_text_margin => $template->get_attr('left_text_margin'),
102 barcode_type => $layout->get_attr('barcode_type'),
103 printing_type => 'BIB',
104 guidebox => $layout->get_attr('guidebox'),
105 font => $layout->get_attr('font'),
106 font_size => $layout->get_attr('font_size'),
771af46 @hgq [fixes #12917357] repurpose callnum_split as split format type.
hgq authored
107 callnum_split => $layout->get_attr('callnum_split'),
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
108 break_rule_string => $layout->get_attr('break_rule_string'),
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
109 justify => $layout->get_attr('text_justify'),
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
110 format_string => $fs,
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
111 text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')),
112 );
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
113 $pdf->Add($label_a->draw_guide_box) if $layout->get_attr('guidebox');
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
114 my $label_a_text = $label_a->create_label();
115 _print_text($label_a_text);
116 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
117 my $label_b = C4::Labels::Label->new(
118 batch_id => $batch_id,
119 item_number => $item->{'item_number'},
120 llx => $llx,
121 lly => $lly,
122 width => $template->get_attr('label_width'),
123 height => $template->get_attr('label_height'),
124 top_text_margin => $template->get_attr('top_text_margin'),
125 left_text_margin => $template->get_attr('left_text_margin'),
126 barcode_type => $layout->get_attr('barcode_type'),
127 printing_type => 'BAR',
128 guidebox => $layout->get_attr('guidebox'),
129 font => $layout->get_attr('font'),
130 font_size => $layout->get_attr('font_size'),
771af46 @hgq [fixes #12917357] repurpose callnum_split as split format type.
hgq authored
131 callnum_split => $layout->get_attr('callnum_split'),
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
132 break_rule_string => $layout->get_attr('break_rule_string'),
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
133 justify => $layout->get_attr('text_justify'),
134 format_string => $layout->get_attr('format_string'),
135 text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')),
136 );
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
137 $pdf->Add($label_b->draw_guide_box) if $layout->get_attr('guidebox');
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
138 my $label_b_text = $label_b->create_label();
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
139 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
140 next LABEL_ITEMS;
2ffd5b7 rel_3_0 moved to HEAD
tipaul authored
141 }
e37f8c2 Labels Cleanup (Part 2 of Many)
Joe Atzberger authored
142 else {
fd4959b tidy up by mason.
sushi authored
143 }
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
144 my $label = C4::Labels::Label->new(
145 batch_id => $batch_id,
146 item_number => $item->{'item_number'},
147 llx => $llx,
148 lly => $lly,
149 width => $template->get_attr('label_width'),
150 height => $template->get_attr('label_height'),
151 top_text_margin => $template->get_attr('top_text_margin'),
152 left_text_margin => $template->get_attr('left_text_margin'),
153 barcode_type => $layout->get_attr('barcode_type'),
154 printing_type => $layout->get_attr('printing_type'),
155 guidebox => $layout->get_attr('guidebox'),
156 font => $layout->get_attr('font'),
157 font_size => $layout->get_attr('font_size'),
771af46 @hgq [fixes #12917357] repurpose callnum_split as split format type.
hgq authored
158 callnum_split => $layout->get_attr('callnum_split'),
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
159 break_rule_string => $layout->get_attr('break_rule_string'),
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
160 justify => $layout->get_attr('text_justify'),
161 format_string => $layout->get_attr('format_string'),
162 text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')),
163 );
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
164 $pdf->Add($label->draw_guide_box) if $layout->get_attr('guidebox');
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
165 my $label_text = $label->create_label();
166 _print_text($label_text) if $label_text;
167 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
168 next LABEL_ITEMS;
64260d4 Inital add of spine label perl files.
sushi authored
169 }
170
13e8945 [20/40] Work on label printing code.
Chris Nighswonger authored
171 $pdf->End();
39d227d [24/40] Adding single/multiple label printing to label export code an…
Chris Nighswonger authored
172
173 exit(1);
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
174
3f5c04b @hgq PT5913845 spine labels, add template, default vals upon add
hgq authored
175 sub _print_text {
176 my $label_text = shift;
177 foreach my $text_line (@$label_text) {
178
179 my $pdf_font = $pdf->Font($text_line->{'font'});
180 my $line = "BT /$pdf_font $text_line->{'font_size'} Tf $text_line->{'text_llx'} $text_line->{'text_lly'} Td ($text_line->{'line'}) Tj ET";
181 $pdf->Add($line);
182 }
183 }
184
9b56b1e [35/40] Work on C4::Labels tests and various bugfixs resulting
Chris Nighswonger authored
185 =head1 NAME
186
187 labels/label-create-pdf.pl - A script for creating a pdf export of labels and label batches in Koha
188
189 =head1 ABSTRACT
190
191 This script provides the means of producing a pdf of labels for items either individually, in groups, or in batches from within Koha.
192
193 =head1 USAGE
194
195 This script is intended to be called as a cgi script although it could be easily modified to accept command line parameters. The script accepts four single
196 parameters and two "multiple" parameters as follows:
197
198 C<batch_id> A single valid batch id to export.
199 C<template_id> A single valid template id to be applied to the current export. This parameter is manditory.
200 C<layout_id> A single valid layout id to be applied to the current export. This parameter is manditory.
201 C<start_label> The number of the label on which to begin the export. This parameter is optional.
202 C<lable_ids> A single valid label id to export. Multiple label ids may be submitted to export multiple labels.
203 C<item_numbers> A single valid item number to export. Multiple item numbers may be submitted to export multiple items.
204
205 B<NOTE:> One of the C<batch_id>, C<label_ids>, or C<item_number> parameters is manditory. However, do not pass a combination of them or bad things might result.
206
207 example:
208 http://staff-client.kohadev.org/cgi-bin/koha/labels/label-create-pdf.pl?batch_id=1&template_id=1&layout_id=5&start_label=1
209
210 =head1 AUTHOR
211
212 Chris Nighswonger <cnighswonger AT foundations DOT edu>
213
214 =head1 COPYRIGHT
215
216 Copyright 2009 Foundations Bible College.
217
218 =head1 LICENSE
219
220 This file is part of Koha.
221
222 Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
223 Foundation; either version 2 of the License, or (at your option) any later version.
224
225 You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
226 Suite 330, Boston, MA 02111-1307 USA
227
228 =head1 DISCLAIMER OF WARRANTY
229
230 Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
231 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
232
233 =cut
Something went wrong with that request. Please try again.