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;
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');
26 my $pdf_file = (@label_ids || @item_numbers ?
"label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
27 print $cgi->header( -type
=> 'application/pdf',
29 -attachment
=> "$pdf_file.pdf",
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);
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'));
44 $llx = $template->get_attr('left_margin');
45 if ($row_count eq $template->get_attr('rows')) {
47 $lly = ($template->get_attr('page_height') - $template->get_attr('top_margin') - $template->get_attr('label_height'));
51 $lly = ($lly - $template->get_attr('row_gap') - $template->get_attr('label_height'));
56 return ($row_count, $col_count, $llx, $lly);
60 my $label_text = shift;
61 foreach my $text_line (@
$label_text) {
62 my $pdf_font = $pdf->Font($text_line->{'font'});
63 my $line = "BT /$pdf_font $text_line->{'font_size'} Tf $text_line->{'text_llx'} $text_line->{'text_lly'} Td ($text_line->{'line'}) Tj ET";
73 my $upperRightX = $template->get_attr('page_width');
74 my $upperRightY = $template->get_attr('page_height');
77 $pdf->Mbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
79 my ($row_count, $col_count, $llx, $lly) = $template->get_label_position($start_label);
82 my $batch_items = $batch->get_attr('items');
85 push(@
{$items}, grep{$_->{'label_id'} == $label_id;} @
{$batch_items});
88 elsif (@item_numbers) {
90 push(@
{$items}, {item_number
=> $_});
94 $items = $batch->get_attr('items');
98 foreach my $item (@
{$items}) {
99 my ($barcode_llx, $barcode_lly, $barcode_width, $barcode_y_scale_factor) = 0,0,0,0;
100 if ($layout->get_attr('printing_type') eq 'ALT') { # we process the ALT style printing type here because it is not an atomic printing type
101 my $label_a = C4
::Labels
::Label
->new(
102 batch_id
=> $batch_id,
103 item_number
=> $item->{'item_number'},
106 width
=> $template->get_attr('label_width'),
107 height
=> $template->get_attr('label_height'),
108 top_text_margin
=> $template->get_attr('top_text_margin'),
109 left_text_margin
=> $template->get_attr('left_text_margin'),
110 barcode_type
=> $layout->get_attr('barcode_type'),
111 printing_type
=> 'BIB',
112 guidebox
=> $layout->get_attr('guidebox'),
113 font
=> $layout->get_attr('font'),
114 font_size
=> $layout->get_attr('font_size'),
115 callnum_split
=> $layout->get_attr('callnum_split'),
116 justify
=> $layout->get_attr('text_justify'),
117 format_string
=> $layout->get_attr('format_string'),
118 text_wrap_cols
=> $layout->get_text_wrap_cols(label_width
=> $template->get_attr('label_width'), left_text_margin
=> $template->get_attr('left_text_margin')),
120 my $label_a_text = $label_a->create_label();
121 _print_text
($label_a_text);
122 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos
($row_count, $col_count, $llx, $lly);
123 my $label_b = C4
::Labels
::Label
->new(
124 batch_id
=> $batch_id,
125 item_number
=> $item->{'item_number'},
128 width
=> $template->get_attr('label_width'),
129 height
=> $template->get_attr('label_height'),
130 top_text_margin
=> $template->get_attr('top_text_margin'),
131 left_text_margin
=> $template->get_attr('left_text_margin'),
132 barcode_type
=> $layout->get_attr('barcode_type'),
133 printing_type
=> 'BAR',
134 guidebox
=> $layout->get_attr('guidebox'),
135 font
=> $layout->get_attr('font'),
136 font_size
=> $layout->get_attr('font_size'),
137 callnum_split
=> $layout->get_attr('callnum_split'),
138 justify
=> $layout->get_attr('text_justify'),
139 format_string
=> $layout->get_attr('format_string'),
140 text_wrap_cols
=> $layout->get_text_wrap_cols(label_width
=> $template->get_attr('label_width'), left_text_margin
=> $template->get_attr('left_text_margin')),
142 my $label_b_text = $label_b->create_label();
143 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos
($row_count, $col_count, $llx, $lly);
148 my $label = C4
::Labels
::Label
->new(
149 batch_id
=> $batch_id,
150 item_number
=> $item->{'item_number'},
153 width
=> $template->get_attr('label_width'),
154 height
=> $template->get_attr('label_height'),
155 top_text_margin
=> $template->get_attr('top_text_margin'),
156 left_text_margin
=> $template->get_attr('left_text_margin'),
157 barcode_type
=> $layout->get_attr('barcode_type'),
158 printing_type
=> $layout->get_attr('printing_type'),
159 guidebox
=> $layout->get_attr('guidebox'),
160 font
=> $layout->get_attr('font'),
161 font_size
=> $layout->get_attr('font_size'),
162 callnum_split
=> $layout->get_attr('callnum_split'),
163 justify
=> $layout->get_attr('text_justify'),
164 format_string
=> $layout->get_attr('format_string'),
165 text_wrap_cols
=> $layout->get_text_wrap_cols(label_width
=> $template->get_attr('label_width'), left_text_margin
=> $template->get_attr('left_text_margin')),
167 my $label_text = $label->create_label();
168 _print_text
($label_text) if $label_text;
169 ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos
($row_count, $col_count, $llx, $lly);
179 labels/label-create-pdf.pl - A script for creating a pdf export of labels and label batches in Koha
183 This script provides the means of producing a pdf of labels for items either individually, in groups, or in batches from within Koha.
187 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
188 parameters and two "multiple" parameters as follows:
190 C<batch_id> A single valid batch id to export.
191 C<template_id> A single valid template id to be applied to the current export. This parameter is manditory.
192 C<layout_id> A single valid layout id to be applied to the current export. This parameter is manditory.
193 C<start_label> The number of the label on which to begin the export. This parameter is optional.
194 C<lable_ids> A single valid label id to export. Multiple label ids may be submitted to export multiple labels.
195 C<item_numbers> A single valid item number to export. Multiple item numbers may be submitted to export multiple items.
197 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.
200 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
204 Chris Nighswonger <cnighswonger AT foundations DOT edu>
208 Copyright 2009 Foundations Bible College.
212 This file is part of Koha.
214 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
215 Foundation; either version 2 of the License, or (at your option) any later version.
217 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,
218 Suite 330, Boston, MA 02111-1307 USA
220 =head1 DISCLAIMER OF WARRANTY
222 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
223 A PARTICULAR PURPOSE. See the GNU General Public License for more details.