使用PDF.js打开PDF文件而不将文件作为查询字符串传递

时间:2016-03-07 12:39:59

标签: javascript php html5 pdf pdf.js

我目前正在使用PDF.js打开PDF文件并且工作正常。

以前我用的是这样的:

http://myapp.mycompany.com/web/viewer.html?file=http://myapp.mycompany.com/my-PDF-file.pdf

我的问题:

由于某些原因,我确实不希望显示我的PDF文件的文件路径,并希望将我的PDF文件移到根目录之外。有没有其他方法可以将pdf文件提供给viewer.html?或者这是好事吗?

注意:我已将所有PDF文件移到根目录之外。那么我现在如何访问PDF?

2 个答案:

答案 0 :(得分:4)

是的,有。调用一些函数(你甚至不需要PDF.js):

http://www.example.com/getPDF.php?fileName=pdfname.pdf

function fileName() {
    $fileName = $_GET['fileName'];
    header("Content-type:application/pdf");
    header("Content-Disposition:inline;filename='{$fileName}'");
    readfile(__DIR__."/../pdfs/private/{$fileName}");
}

答案 1 :(得分:0)

使用rawurlencode编码'/ getP DF.php?filename = pdfname.pdf'部分:

"http://myapp.mycompany.com/web/viewer.html?file=".rawurlencode("/getP‌​DF.php?filename=".rawurlencode("pdfname.pdf"))