ryddler has asked for the wisdom of the Perl Monks concerning the following question:
I have a strange problem that seems to revolve around the headers I am sending to the browser in order to properly send a PDF file. The script creates an Excel object, fills in a sheet with data, and then prints it out to PDF. From there, the PDF is opened, binmode'd and read into a scalar.
The following snippet is what I am currently using:
my ($offset,$bytes,$buffer,$contents); open(PDF, "<$print_pdf") || print_debug("Couldn't open file $print +_pdf");; $offset = 0; $contents = ''; binmode PDF; until(eof(PDF)) { $bytes += read(PDF,$buffer, 1048576, $offset); $offset += 1048576; $contents .= $buffer; } close PDF; print header( -type => 'application/pdf', -Content_Disposition => "inline; filename=charges.pdf", -Content_Length => "$bytes" ); #print "Content-Disposition: inline; filename=charges.pdf\n"; #print "Content-Length: $bytes\n"; #print "Content-Type: application/pdf\n\n"; #binmode STDOUT; print $contents;
The problem I'm facing, is that the browser (IE) "loads" the script three times (one URL click executes the script three times). Netscape 6 does it twice. So the script pops open three Excel objects, creates three PDF files, and ultimately sends back one PDF to the browser.
I have tried with/without the binmode STDOUT; line with no difference. I tried Using the lines that are commented out instead of the print header function (CGI.pm), and nothing I've tried seems to resolve the problem.
Have any fellow monks had any similar experiences?
ryddler
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Content headers for PDF?
by shotgunefx (Parson) on Jun 09, 2001 at 02:48 UTC | |
by ryddler (Monk) on Jun 09, 2001 at 03:20 UTC | |
by shotgunefx (Parson) on Jun 10, 2001 at 04:14 UTC |