Is it possible to render a pdf in a browser using PERL? What I have is a flash application that sends the rendered pdf binary to perl. The pdf is generated from AlivePDF.
#!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&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] => $tmp[1] }split(/&/,$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->param('POSTDATA');
print "Content-Type: application/pdf\r\n";
print "Content-Length: " . length($pdf) . "\r\n";
print "Content-Disposition :$method\n\n";
print $pdf;
The problem is that I want to actually render what a pdf will look like. I can save that binary code and open it manually in Adobe Reader and it renders properly.
I would like for it to render in the browser, but I don't know how to get it to.
Currently the output (what the browser displays), looks like this:
Content-Type: application/pdf
Content-Length: 432785
Content-disposition:inline; filename="test.pdf"
%PDF-1.5
1 0 obj
<</Type /Pages
/Kids [3 0 R 5 0 R]
/Count 2>>
endobj
3 0 obj
<</Type /Page
/Parent 1 0 R
/MediaBox [0 0 612.00 792.00]
/Resources 2 0 R
This is only part of the displayed file, but I hope this helps. I don't want the code to display, I want it to look graphical. If I download this file, and change the extension to .pdf, it works perfectly.
I do not have the Flash app that creates the PDF in the request body, but I verified it against the output of a static resource with the same response headers.
Content-Disposition
is the crucial one. This was tested in Konqueror with the Okular KPart and works, I fully expect other browsers/plug-in combinations to also work.Be aware that you are mixing GET and POST parameters. Learn how to write secure CGI programs.