Browse Source

Bug 7952 - PDF::Reuse under plack writes to console STDOUT instead to browser

Without name option to prFile, PDF::Reuse opens '-' file which is real
console STDOUT on plack so pdf file gets emited to terminal instead of
sending it to browser.

This change creates temporary file using File::Temp, pass it to PDF::Reuse
and then reads it back and prints it out for plack (or CGI) to pick up.

Test secenario:

1. Home › Tools › Patron Card Creator › Manage Card Batches
2. select batch checkbox and click Export
3. select template and click Export
4. click on pdf file to download it

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
3.10.x
Dobrica Pavlinusic 12 years ago
committed by Paul Poulain
parent
commit
dc1ccb1d74
  1. 15
      C4/Creators/PDF.pm

15
C4/Creators/PDF.pm

@ -21,6 +21,7 @@ use strict;
use warnings;
use PDF::Reuse;
use PDF::Reuse::Barcode;
use File::Temp;
BEGIN {
use version; our $VERSION = qv('3.07.00.049');
@ -42,7 +43,12 @@ sub new {
delete($opts{InitVars});
prDocDir($opts{'DocDir'}) if $opts{'DocDir'};
delete($opts{'DocDir'});
prFile(%opts);
my $fh = File::Temp->new( UNLINK => 0, SUFFIX => '.pdf' );
$opts{Name} = $self->{filename} = "$fh"; # filename
close $fh; # we need just filename
prFile(\%opts);
bless ($self, $type);
return $self;
}
@ -52,6 +58,13 @@ sub End {
# if the pdf stream is utf8, explicitly set it to utf8; this avoids at lease some wide character errors -chris_n
utf8::encode($PDF::Reuse::stream) if utf8::is_utf8($PDF::Reuse::stream);
prEnd();
# slurp temporary filename and print it out for plack to pick up
local $/ = undef;
open(my $fh, '<', $self->{filename}) || die "$self->{filename}: $!";
print <$fh>;
close $fh;
unlink $self->{filename};
}
sub Add {

Loading…
Cancel
Save