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


In reply to Content headers for PDF? by ryddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.