[Koha-cvs] koha/barcodes label-print-opus-pdf.pl [dev_week]

Mason James szrj1m at yahoo.com
Mon Dec 4 06:18:44 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		dev_week
Changes by:	Mason James <sushi>	06/12/04 05:18:44

Modified files:
	barcodes       : label-print-opus-pdf.pl 

Log message:
	RT:2268 Oops, previously commited a way old version of this file from savannah, commiting current one again, with mod to NOT write to tmp file, but pass directly to browser.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/barcodes/label-print-opus-pdf.pl?cvsroot=koha&only_with_tag=dev_week&r1=1.2.4.1&r2=1.2.4.2

Patches:
Index: label-print-opus-pdf.pl
===================================================================
RCS file: /sources/koha/koha/barcodes/label-print-opus-pdf.pl,v
retrieving revision 1.2.4.1
retrieving revision 1.2.4.2
diff -u -b -r1.2.4.1 -r1.2.4.2
--- label-print-opus-pdf.pl	2 Oct 2006 22:01:39 -0000	1.2.4.1
+++ label-print-opus-pdf.pl	4 Dec 2006 05:18:44 -0000	1.2.4.2
@@ -1,62 +1,197 @@
 #!/usr/bin/perl
 
-#use lib '/usr/local/opus-dev/intranet/modules';
-#use C4::Context("/etc/koha-opus-dev.conf");
+#----------------------------------------------------------------------
+# this script is really divided into 2 differenvt section,
+
+# the first section creates, and defines the new PDF file the barcodes
+# using PDF::Reuse::Barcode, then saves the file to disk.
+
+# the second section then opens the pdf file off disk, and places the spline label
+# text in the left-most column of the page. then save the file again.
+
+# the reason for this goofyness, it that i couldnt find a single perl package that handled both barcodes and decent text placement.
+
+# use lib '/usr/local/opus-dev/intranet/modules';
+# use C4::Context("/etc/koha-opus-dev.conf");
 
 use strict;
 use CGI;
 use C4::Labels;
 use C4::Auth;
-use C4::Bull;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::Context;
+use HTML::Template;
 use PDF::Reuse;
 use PDF::Reuse::Barcode;
-use PDF::Report;
-use PDF::Create;
-use PDF::Labels;
-use Acme::Comment;
-use Data::Dumper;
-warn "-------";
+use POSIX;
+use Text::Wrap;
 
-my $htdocs_path = C4::Context->config('intrahtdocs');
-my $cgi         = new CGI;
+#use Data::Dumper;
+#use Acme::Comment;
 
-my $pdf = new PDF::Labels(
-    $PDF::Labels::PageFormats[1],
-    filename   => "$htdocs_path/barcodes/opus.pdf",
-    Author     => 'PDF Labelmaker',
-    'PageMode' => 'UseOutlines',
-    Title      => 'My Labels'
-);
+$Text::Wrap::columns   = 39;
+$Text::Wrap::separator = "\n";
 
-warn "$htdocs_path/barcodes/opus.pdf";
+my $htdocs_path = C4::Context->config('intrahtdocs');
+my $cgi         = new CGI;
+my $spine_text  = "";
 
+# get the printing settings
+my $conf_data    = get_label_options();
 my @resultsloop = get_label_items();
-
-#warn Dumper @resultsloop;
-warn Dumper $pdf->{'filename'};
-
-$pdf->setlabel(0);    # Start with label 5 on first page
-
-foreach my $result (@resultsloop) {
-    warn Dumper $result;
-    $pdf->label( $result->{'itemtype'}, $result->{'number'}, 'LAK',
-        $result->{'barcode'} );
-    $pdf->label( $result->{'itemtype'}, $result->{'dewey'}, 'LAK',
-        $result->{'barcode'} );
-
+my $barcodetype  = $conf_data->{'barcodetype'};
+my $printingtype = $conf_data->{'printingtype'};
+my $guidebox     = $conf_data->{'guidebox'};
+my $startrow     = $conf_data->{'startrow'};
+
+# if none selected, then choose 'both'
+if ( !$printingtype ) {
+    $printingtype = 'both';
 }
-warn "HERE";
-$pdf->close();
 
-#--------------------------------------------------
+# opus paper dims. in *millimeters*
+# multiply values by '2.83465', to find their value in Postscript points.
 
-use PDF::Reuse;
-prFile("$htdocs_path/barcodes/opus1.pdf");
-prDoc("$htdocs_path/barcodes/opus.pdf");
+# $xmargin           = 12;
+# $label_height     = 34;
+# $label_width      = 74;
+# $x_pos_spine      = 12;
+# $pageheight       = 304;
+# $pagewidth       = 174;
+# $line_spacer      = 10;
+# $label_rows       = 8;
+
+# sheet dimensions in PS points.
+
+my $top_margin       = 7;
+my $left_margin      = 34;
+my $top_text_margin  = 20;
+my $left_text_margin = 10;
+my $label_height     = 96;
+my $spine_width      = 210;
+my $colspace         = 9;
+my $rowspace         = 11;
+my $x_pos_spine      = 36;
+my $pageheight       = 861;
+my $pagewidth        = 493;
+my $line_spacer      = 10;
+my $label_rows       = 8;
+
+# setting up the pdf doc
+#remove the file before write, for testing
+#unlink "$htdocs_path/barcodes/new.pdf";
+#prFile("$htdocs_path/barcodes/new.pdf");
+#prLogDir("$htdocs_path/barcodes");
+
+prInitVars();    # To initiate ALL global variables and tables
+$| = 1;
+print STDOUT "Content-Type: application/pdf \n\n";
+prFile();
+
+prMbox( 0, 0, $pagewidth, $pageheight );
+prFont('courier');    # Just setting a font
+prFontSize(9);
+
+my $str;
+
+#warn "STARTROW = $startrow\n";
+
+my $y_pos_initial = ( ( $pageheight - $top_margin ) - $label_height );
+my $y_pos_initial_startrow =
+  ( ( $pageheight - $top_margin ) - ( $label_height * $startrow ) );
+my $y_pos = $y_pos_initial_startrow;
+
+#warn "Y POS INITAL : $y_pos_initial";
+#warn "Y POS : $y_pos";
+#warn "Y START ROW = $y_pos_initial_startrow";
+
+my $page_break_count = $startrow;
+my $codetype         = 'Code39';
+
+#do page border
+# commented out coz it was running into the side-feeds of the paper.
+# drawbox( 0, 0 , $pagewidth, $pageheight );
+
+my $item;
+
+# for loop
+my $i2 = 1;
+
+foreach $item (@resultsloop) {
+    my $x_pos_spine_tmp = $x_pos_spine;
+
+    for ( 1 .. 2 ) {
+
+        if ( $guidebox == 1 ) {
+            warn
+"COUNT1, PBREAKCNT=$page_break_count,  y=$y_pos, labhght = $label_height";
+            drawbox( $x_pos_spine_tmp, $y_pos, $spine_width, $label_height );
+        }
+
+        #-----------------draw spine text
+        if ( $printingtype eq 'spine' || $printingtype eq 'both' ) {
+
+            #warn "PRINTTYPE = $printingtype";
+
+            # add your printable fields manually in here
+            my @fields = qw (itemtype dewey isbn classification);
+            my $vPos   = ( $y_pos + ( $label_height - $top_text_margin ) );
+            my $hPos   = ( $x_pos_spine_tmp + $left_text_margin );
+            foreach my $field (@fields) {
+
+               # if the display option for this field is selected in the DB,
+               # and the item record has some values for this field, display it.
+                if ( $conf_data->{"$field"} && $item->{"$field"} ) {
+
+                    #warn "CONF_TYPE = $field";
+
+                    # get the string
+                    $str = $item->{"$field"};
+
+                    # strip out naughty existing nl/cr's
+                    $str =~ s/\n//g;
+                    $str =~ s/\r//g;
+
+                    # chop the string up into _upto_ 12 chunks
+                    # and seperate the chunks with newlines
+
+                    $str = wrap( "", "", "$str" );
+                    $str = wrap( "", "", "$str" );
+
+                    # split the chunks between newline's, into an array
+                    my @strings = split /\n/, $str;
+
+                    # then loop for each string line
+                    foreach my $str (@strings) {
+
+                        warn "HPOS ,  VPOS $hPos, $vPos ";
+                        prText( $hPos, $vPos, $str );
+                        $vPos = $vPos - $line_spacer;
+                    }
+                }    # if field is valid
+            }    # foreach   @field
+        }    #if spine
+
+        $x_pos_spine_tmp = ( $x_pos_spine_tmp + $spine_width + $colspace );
+    }    # for 1 ..2
+    warn " $y_pos - $label_height - $rowspace";
+    $y_pos = ( $y_pos - $label_height - $rowspace );
+    warn " $y_pos - $label_height - $rowspace";
+
+    #-----------------draw spine text
+
+    # the gaylord labels have 8 rows per sheet, this pagebreaks after 8 rows
+    if ( $page_break_count == $label_rows ) {
+        prPage();
+        $page_break_count = 0;
+        $i2               = 0;
+        $y_pos            = $y_pos_initial;
+    }
+    $page_break_count++;
+    $i2++;
+}
 prEnd();
 
-print $cgi->redirect("/intranet-tmpl/barcodes/opus1.pdf");
+#print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");
 





More information about the Koha-cvs mailing list