我想向用户显示PDF文件.我使用cgi来显示pdf的原因是我想跟踪pdf的点击次数,并隐藏保存的pdf的真实位置.
我一直在互联网上搜索,只发现如何向用户显示保存对话框并创建pdf,而不是向用户显示文件.
我想要的是向用户显示我的pdf文件,而不是创建或下载 pdf.这是我从官方php文档中得到的:
<?php
header('Content-type: application/pdf');
readfile('the.pdf');
?>
Run Code Online (Sandbox Code Playgroud)
还有我的google-search-result perl代码:
open(PDF, "the.pdf") or die "could not open PDF [$!]";
binmode PDF;
my $output = do { local $/; <PDF> };
close (PDF);
print "Content-Type: application/pdf\n";
print "Content-Length: " .length($output) . "\n\n";
print $output
Run Code Online (Sandbox Code Playgroud)
如果你在红宝石上做,请告诉我.但我不确定我的服务器是否支持rails.
很抱歉,如果我的代码与显示pdf的方法相距太远,因为我对pdf处理以及如何实现此问题一无所知.
让我们假设用户拥有Adobe Reader插件.那么,如何解决我的问题呢?
编辑:我想显示普通的pdf文件.我的主要目的:跟踪我的pdf文件并使用一些花哨的网址.
编辑:这是我的主要PHP代码:
<?php
$file='/files/the.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
@readfile($file);
?>
Run Code Online (Sandbox Code Playgroud)
编辑:现在代码正常工作.但是加载进度条(在Adobe Reader X插件上)没有显示出来.为什么?有人可以帮帮我吗?这是我的主要代码:
<?php
$file='./files/the.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: …Run Code Online (Sandbox Code Playgroud)