7 use Sys::Syslog qw(syslog);
10 use C4::Labels::Batch 1.000000;
11 use C4::Labels::Template 1.000000;
12 use C4::Labels::Layout 1.000000;
13 use C4::Labels::PDF 1.000000;
14 use C4::Labels::Label 1.000000;
18 my $batch_id = $cgi->param('batch_id') if $cgi->param('batch_id');
19 my $template_id = $cgi->param('template_id') || undef;
20 my $layout_id = $cgi->param('layout_id') || undef;
21 my $start_label = $cgi->param('start_label') || 1;
22 my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
23 my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
27 my $pdf_file = (@label_ids || @item_numbers ? "label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
28 print $cgi->header( -type => 'application/pdf',
30 -attachment => "$pdf_file.pdf",
33 my $pdf = C4::Labels::PDF->new(InitVars => 0);
34 my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
35 my $template = C4::Labels::Template->retrieve(template_id => $template_id, profile_id => 1);
36 my $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
38 sub _calc_next_label_pos {
39 my ($row_count, $col_count, $llx, $lly) = @_;
40 if ($col_count lt $template->get_attr('cols')) {
41 $llx = ($llx + $template->get_attr('label_width') + $template->get_attr('col_gap'));
45 $llx = $template->get_attr('left_margin');
46 if ($row_count eq $template->get_attr('rows')) {
48 $lly = ($template->get_attr('page_height') - $template->get_attr('top_margin') - $template->get_attr('label_height'));
52 $lly = ($lly - $template->get_attr('row_gap') - $template->get_attr('label_height'));
57 return ($row_count, $col_count, $llx, $lly);
61 my $label_text = shift;
62 foreach my $text_line (@$label_text) {
63 my $pdf_font = $pdf->Font($text_line->{'font'});
64 my $line = "BT /$pdf_font $text_line->{'font_size'} Tf $text_line->{'text_llx'} $text_line->{'text_lly'} Td ($text_line->{'line'}) Tj ET";
74 my $upperRightX = $template->get_attr('page_width');
75 my $upperRightY = $template->get_attr('page_height');
78 $pdf->Mbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
80 my ($row_count, $col_count, $llx, $lly) = $template->get_label_position($start_label);
83 my $batch_items = $batch->get_attr('items');
86 push(@{$items}, grep{$_->{'label_id'} == $label_id;} @{$batch_items});
89 elsif (@item_numbers) {
91 push(@{$items}, {item_number => $_});
95 $items = $batch->get_attr('items');
99 foreach my $item (@{$items}) {
100 my ($barcode_llx, $barcode_lly, $barcode_width, $barcode_y_scale_factor) = 0,0,0,0;
101 if ($layout->get_attr('printing_type') eq 'ALT') { # we process the ALT style printing type here because it is not an atomic printing type
102 my $label_a = C4::Labels::Label->new(
103 batch_id => $batch_id,
104 item_number => $item->{'item_number'},
107 width => $template->get_attr('label_width'),
108 height => $template->get_attr('label_height'),
109 top_text_margin => $template->get_attr('top_text_margin'),
110 left_text_margin => $template->get_attr('left_text_margin'),
111 barcode_type => $layout->get_attr('barcode_type'),
112 printing_type => 'BIB',
113 guidebox => $layout->get_attr('guidebox'),
114 font => $layout->get_attr('font'),
115 font_size => $layout->get_attr('font_size'),
116 callnum_split => $layout->get_attr('callnum_split'),
117 justify => $layout->get_attr('text_justify'),
118 format_string => $layout->get_attr('format_string'),
119 text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')),
121 my $label_a_text = $label_a->create_label();
122 _print_text($label_a_text);
123 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
124 my $label_b = C4::Labels::Label->new(
125 batch_id => $batch_id,
126 item_number => $item->{'item_number'},
129 width => $template->get_attr('label_width'),
130 height => $template->get_attr('label_height'),
131 top_text_margin => $template->get_attr('top_text_margin'),
132 left_text_margin => $template->get_attr('left_text_margin'),
133 barcode_type => $layout->get_attr('barcode_type'),
134 printing_type => 'BAR',
135 guidebox => $layout->get_attr('guidebox'),
136 font => $layout->get_attr('font'),
137 font_size => $layout->get_attr('font_size'),
138 callnum_split => $layout->get_attr('callnum_split'),
139 justify => $layout->get_attr('text_justify'),
140 format_string => $layout->get_attr('format_string'),
141 text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')),
143 my $label_b_text = $label_b->create_label();
144 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
149 my $label = C4::Labels::Label->new(
150 batch_id => $batch_id,
151 item_number => $item->{'item_number'},
154 width => $template->get_attr('label_width'),
155 height => $template->get_attr('label_height'),
156 top_text_margin => $template->get_attr('top_text_margin'),
157 left_text_margin => $template->get_attr('left_text_margin'),
158 barcode_type => $layout->get_attr('barcode_type'),
159 printing_type => $layout->get_attr('printing_type'),
160 guidebox => $layout->get_attr('guidebox'),
161 font => $layout->get_attr('font'),
162 font_size => $layout->get_attr('font_size'),
163 callnum_split => $layout->get_attr('callnum_split'),
164 justify => $layout->get_attr('text_justify'),
165 format_string => $layout->get_attr('format_string'),
166 text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')),
168 my $label_text = $label->create_label();
169 _print_text($label_text) if $label_text;
170 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
180 labels/label-create-pdf.pl - A script for creating a pdf export of labels and label batches in Koha
184 This script provides the means of producing a pdf of labels for items either individually, in groups, or in batches from within Koha.
188 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
189 parameters and two "multiple" parameters as follows:
191 C<batch_id> A single valid batch id to export.
192 C<template_id> A single valid template id to be applied to the current export. This parameter is manditory.
193 C<layout_id> A single valid layout id to be applied to the current export. This parameter is manditory.
194 C<start_label> The number of the label on which to begin the export. This parameter is optional.
195 C<lable_ids> A single valid label id to export. Multiple label ids may be submitted to export multiple labels.
196 C<item_numbers> A single valid item number to export. Multiple item numbers may be submitted to export multiple items.
198 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.
201 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
205 Chris Nighswonger <cnighswonger AT foundations DOT edu>
209 Copyright 2009 Foundations Bible College.
213 This file is part of Koha.
215 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
216 Foundation; either version 2 of the License, or (at your option) any later version.
218 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,
219 Suite 330, Boston, MA 02111-1307 USA
221 =head1 DISCLAIMER OF WARRANTY
223 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
224 A PARTICULAR PURPOSE. See the GNU General Public License for more details.