rel_3_0 moved to HEAD
[koha.git] / barcodes / label-print-opus-pdf.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19 use CGI;
20 use C4::Labels;
21 use C4::Auth;
22 use C4::Output;
23 use C4::Interface::CGI::Output;
24 use C4::Context;
25 use PDF::Reuse;
26 use PDF::Reuse::Barcode;
27 use POSIX;
28 use Text::Wrap;
29
30
31 $Text::Wrap::columns   = 39;
32 $Text::Wrap::separator = "\n";
33
34 my $htdocs_path = C4::Context->config('intrahtdocs');
35 my $cgi         = new CGI;
36 my $spine_text  = "";
37
38 # get the printing settings
39 my $conf_data    = get_label_options();
40 my @resultsloop  = get_label_items();
41 my $barcodetype  = $conf_data->{'barcodetype'};
42 my $printingtype = $conf_data->{'printingtype'};
43 my $guidebox     = $conf_data->{'guidebox'};
44 my $startrow     = $conf_data->{'startrow'};
45
46 # if none selected, then choose 'both'
47 if ( !$printingtype ) {
48     $printingtype = 'both';
49 }
50
51 # opus paper dims. in *millimeters*
52 # multiply values by '2.83465', to find their value in Postscript points.
53
54 # $xmargin           = 12;
55 # $label_height     = 34;
56 # $label_width      = 74;
57 # $x_pos_spine      = 12;
58 # $pageheight       = 304;
59 # $pagewidth       = 174;
60 # $line_spacer      = 10;
61 # $label_rows       = 8;
62
63 # sheet dimensions in PS points.
64
65 my $top_margin       = 7;
66 my $left_margin      = 34;
67 my $top_text_margin  = 20;
68 my $left_text_margin = 10;
69 my $label_height     = 96;
70 my $spine_width      = 210;
71 my $colspace         = 9;
72 my $rowspace         = 11;
73 my $x_pos_spine      = 36;
74 my $pageheight       = 861;
75 my $pagewidth        = 493;
76 my $line_spacer      = 10;
77 my $label_rows       = 8;
78
79 # setting up the pdf doc
80 #remove the file before write, for testing
81 #unlink "$htdocs_path/barcodes/new.pdf";
82 #prFile("$htdocs_path/barcodes/new.pdf");
83 #prLogDir("$htdocs_path/barcodes");
84
85 # fix, no longer writes to temp dir
86 prInitVars();    # To initiate ALL global variables and tables
87 $| = 1;
88 print STDOUT "Content-Type: application/pdf \n\n";
89 prFile();
90
91 prMbox( 0, 0, $pagewidth, $pageheight );
92 prFont('courier');    # Just setting a font
93 prFontSize(9);
94
95 my $str;
96
97 my $y_pos_initial = ( ( $pageheight - $top_margin ) - $label_height );
98 my $y_pos_initial_startrow =
99   ( ( $pageheight - $top_margin ) - ( $label_height * $startrow ) );
100 my $y_pos = $y_pos_initial_startrow;
101
102 my $page_break_count = $startrow;
103 my $codetype         = 'Code39';
104
105 #do page border
106 # commented out coz it was running into the side-feeds of the paper.
107 # drawbox( 0, 0 , $pagewidth, $pageheight );
108
109 my $item;
110
111 # for loop
112 my $i2 = 1;
113
114 foreach $item (@resultsloop) {
115     my $x_pos_spine_tmp = $x_pos_spine;
116
117     for ( 1 .. 2 ) {
118
119         if ( $guidebox == 1 ) {
120             warn
121 "COUNT1, PBREAKCNT=$page_break_count,  y=$y_pos, labhght = $label_height";
122             drawbox( $x_pos_spine_tmp, $y_pos, $spine_width, $label_height );
123         }
124
125         #-----------------draw spine text
126         if ( $printingtype eq 'spine' || $printingtype eq 'both' ) {
127
128             #warn "PRINTTYPE = $printingtype";
129
130             # add your printable fields manually in here
131             my @fields = qw (itemtype dewey isbn classification);
132             my $vPos   = ( $y_pos + ( $label_height - $top_text_margin ) );
133             my $hPos   = ( $x_pos_spine_tmp + $left_text_margin );
134             foreach my $field (@fields) {
135
136                # if the display option for this field is selected in the DB,
137                # and the item record has some values for this field, display it.
138                 if ( $conf_data->{"$field"} && $item->{"$field"} ) {
139
140                     #warn "CONF_TYPE = $field";
141
142                     # get the string
143                     $str = $item->{"$field"};
144
145                     # strip out naughty existing nl/cr's
146                     $str =~ s/\n//g;
147                     $str =~ s/\r//g;
148
149                     # chop the string up into _upto_ 12 chunks
150                     # and seperate the chunks with newlines
151
152                     $str = wrap( "", "", "$str" );
153                     $str = wrap( "", "", "$str" );
154
155                     # split the chunks between newline's, into an array
156                     my @strings = split /\n/, $str;
157
158                     # then loop for each string line
159                     foreach my $str (@strings) {
160
161                         warn "HPOS ,  VPOS $hPos, $vPos ";
162                         prText( $hPos, $vPos, $str );
163                         $vPos = $vPos - $line_spacer;
164                     }
165                 }    # if field is valid
166             }    # foreach   @field
167         }    #if spine
168
169         $x_pos_spine_tmp = ( $x_pos_spine_tmp + $spine_width + $colspace );
170     }    # for 1 ..2
171     warn " $y_pos - $label_height - $rowspace";
172     $y_pos = ( $y_pos - $label_height - $rowspace );
173     warn " $y_pos - $label_height - $rowspace";
174
175     #-----------------draw spine text
176
177     # the gaylord labels have 8 rows per sheet, this pagebreaks after 8 rows
178     if ( $page_break_count == $label_rows ) {
179         prPage();
180         $page_break_count = 0;
181         $i2               = 0;
182         $y_pos            = $y_pos_initial;
183     }
184     $page_break_count++;
185     $i2++;
186 }
187 prEnd();
188
189 #print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");
190