Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Opening PDF through CGI

by nobull (Friar)
on May 26, 2006 at 16:58 UTC ( #551908=note: print w/replies, xml ) Need Help??


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";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://551908]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2021-04-15 23:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?