Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to add in the following HTTP header</p> <pre><code>print "Content-Transfer-Encoding: binary\n"; </code></pre> <p>The following is working for me to read a pdf file and display it:</p> <pre><code>use strict; use warnings; my $file = "discover.pdf"; # a pdf I happen to have my $pdf; open (my $fh, $file); binmode $fh; # set the file handle to binary mode while (&lt;$fh&gt;){ $pdf .= $_; } # read it all into a string; close ($fh); showPdf($pdf); # call the display function sub showPdf { my $pdf = shift; my $file = shift || "new.pdf"; # if no name is given use this my $method = shift || "Content-disposition:inline; filename='$file'"; # default method my $size = length($pdf); print "Content-Type: application/pdf\n"; print "Content-Length: $size\n"; print "$method\n"; print "Content-Transfer-Encoding: binary\n\n"; # blank line to separate headers print $pdf; } </code></pre> <p>The same function can be added to the original code and should work like this:</p> <pre><code>#!C:\Perl\bin\perl.exe ## BEGIN { $ENV{PATH} = ''; delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; } use strict; use warnings; no warnings qw (redefine closure); use CGI; my $CGI = new CGI(); #name=generated.pdf&amp;method=inline these are passed via the URL and are in the environmental variable QUERY_STRING my %nv_pairs = map{my @tmp = split(/=/,$_);$tmp[0] =&gt; $tmp[1] }split(/&amp;/,$ENV{QUERY_STRING}); my $name = $nv_pairs{name}; my $method = $nv_pairs{method}; #Raw Data is stored in the POST Parameter POSTDATA my $pdf = $CGI-&gt;param('POSTDATA'); showPdf($pdf, $name, $method); sub showPdf { my $pdf = shift; my $file = shift || "new.pdf"; # if no name is given use this my $method = shift || "Content-disposition:inline; filename='$file'"; # default method my $size = length($pdf); print "Content-Type: application/pdf\n"; print "Content-Length: $size\n"; print "$method\n"; print "Content-Transfer-Encoding: binary\n\n"; # blank line to separate headers print $pdf; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload