I'm working on a program that uses CGI::Application as its base. Just about everything is working except I am unable to display an Acrobat file to the user. I've read descriptions of how to do this and have followed them, but am having no luck getting it to actually work.

Here's some snippets of code:

sub view_file { my ($self) = @_; my $cgi = $self->query; my $cgi_vars = {$cgi->Vars}; my $order = EN::OrdersDB::OrdersUpdate->retrieve( $cgi_vars->{order_id} ); my $filename = $order->dlc_file_num . ".pdf"; my $file_blob = $order->pdf_files->pdf_file; my $file_size = length ($file_blob); $self->header_props( -type => "application/pdf", -attachment => $filename, -Content_Length => $file_size, -Content_Transfer_Encoding => "binary", ); return $file_blob; }

The resulting output looks something like this in the web browser:


Content-Disposition: attachment; filename="DLC12345.pdf" Content-lengt +h: 8741 Content-transfer-encoding: binary Content-Type: application/p +df %PDF-1.4 %âãÏÓ 8 0 obj << /Linearized +1 /O 10 /H ( 694 170 ) /L 8741 /E 6007 /N 2 /T 8464 >> endobj xref 8 +14 0000000016 00000 n 0000000624 00000

... and so on. All of the expected stuff appears to be there, but it is displayed in the browser as if the Content-Type had not been changed to application/pdf.

Any suggestions?

Wally Hartshorn

(Plug: Visit JavaJunkies, PerlMonks for Java)

update (broquaint): added <code> tags to the output


In reply to Displaying PDF files via CGI::Application by Wally Hartshorn

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.