使用pdf.js查看器打开一个外部文件

Open a external file using pdf.js viewer

本文关键字:一个 文件 外部 js pdf 使用      更新时间:2023-10-16

我正在使用pdf.js查看器在网页中显示pdf文件。在服务器端,我有一个文件夹查看器。在这个文件夹里我有脚本&内容文件夹。

在服务器脚本中,

// Configuration
app.configure(function(){
app.use(express.static(__dirname + '/scripts'));
});

因此,如果我放置localhost/viewer.html来显示查看器。

要打开一个文件,我放置localhost/viewer.html?file=sample.pdf。如果viewer.html&sample.pdf在同一个文件夹中。但我想从脚本文件夹

中的viewer.html的内容文件夹加载一个输入文件

最简单的方法是用不同的根路径设置多个静态中间件:

app.use('/', express.static(__dirname + '/scripts'));
app.use('/content', express.static(__dirname + '/content'));

请注意,您必须重写PDF查看器才能从http://yourhost/pdf/而不是http://yourhost/下载文件。