[followup] (bug #4051) fix default values
[koha.git] / labels / label-print-pdf.pl
index 8855f9f..51fefe1 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 use strict;
+use warnings;
 use CGI;
 use C4::Labels;
 use C4::Auth;
@@ -105,6 +106,17 @@ my $lowerLeftY  = 0;
 my $upperRightX = $page_width;
 my $upperRightY = $page_height;
 
+warn "Active profile: " . ($profile->{prof_id} || "None") if $DEBUG;
+
+#### PRINT PRELIMINARY DATA ####
+print $cgi->header( -type => 'application/pdf', -attachment => 'barcode.pdf' ); 
+    # Don't print header until very last possible moment
+    # That way if error or die occurs, fatals_to_browser will still work.
+    # After we print this header, there is no way back to HTML.  All we can do is deliver PDF.
+prInitVars();
+$| = 1;
+prFile();   # No args means to STDOUT
+prCompress(1);  # turn on zip compression which dramatically reduces file size
 prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY );
 
 my $codetype; # = 'Code39';
@@ -147,7 +159,6 @@ if ( $DEBUG && $profile->{'prof_id'} ) {
     warn "No profile associated so no adjustment applied.";
 }
 
-my $item;
 my ( $i, $i2 );    # loop counters
 
 #warn " $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY";
@@ -180,7 +191,7 @@ else {
 #    main foreach loop
 #
 
-foreach $item (@resultsloop) {
+foreach my $item (@resultsloop) {
     warn "Label parameters: xpos=$x_pos, ypos=$y_pos, lblwid=$label_width, lblhig=$label_height" if $DEBUG;
     if ( $printingtype eq 'BAR' ) {
         drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox;