是否可以使用 PERL 在浏览器中呈现 pdf?我拥有的是一个将渲染的 pdf 二进制文件发送到 perl 的 flash 应用程序。pdf 是从 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;
问题是我想实际渲染 pdf 的样子。我可以保存该二进制代码并在 Adobe Reader 中手动打开它并正确呈现。
我想让它在浏览器中呈现,但我不知道如何得到它。
当前输出(浏览器显示的内容)如下所示:
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
这只是显示文件的一部分,但我希望这会有所帮助。我不想显示代码,我希望它看起来像图形。如果我下载这个文件,并将扩展名更改为 .pdf,它可以完美运行。