in reply to Re: Opening PDF through CGI
in thread Opening PDF through CGI
print header('application/pdf'), do { open my $fh, '<:raw', 'minimal.pdf' or die "D'Oh! $!\n"; local $\; <$fh>; };
Due to the funny way CGI::header() operates under mod_perl it is advisable to always print the result of CGI::header immediately and never defer it. In this particular case it probably doesn't matter but one day it may.
print header('application/pdf'); { open my $fh, '<:raw', 'minimal.pdf' or die "D'Oh! $!\n"; local $\; print <$fh>; };
Note: the above code slurps the whole PDF into memory. I prefer to use File::Copy
use File::Copy 'copy'; print header('application/pdf'); copy 'minimal.pdf', \*STDOUT or die "D'Oh! $!\n";
|
---|
In Section
Seekers of Perl Wisdom