【发布时间】:2017-11-03 12:30:15
【问题描述】:
我想将 PDF.js(或 Viewer.js)与我已经从服务器下载文件的 Flask 应用程序一起使用。
而不是使用
PDFJS.getDocument('helloworld.pdf')
我想查看通过 Ajax 调用下载到浏览器的 pdf。 (这允许更多的服务器控制向客户端提供仅允许用户访问的文件)
例如在 Flask 中
@mayapp.route('/files/<int:file_id>', methods=['GET'])
def file_access(file_id: int=None):
// lookup access and file path in database, get file
return send_file(file_path)
在客户端:
fetchData: function () {
axios({
method: 'get',
url: '/myapp/files/' + this.file_id,
dataType: ...,
headers: ...,
data: {}
})
.then((response) => {
this.file = response.data
})
}
然后我想将此.file 输入 PDF.js 以查看它。
例如根据Flask / postgres - display pdf with PDFJS 使用base64 编码的字符串:
var doc = PDFJS.getDocument({data: pdfData})
但我不知道如何准确呈现文档。有任何想法吗?
【问题讨论】:
标签: javascript pdf vue.js pdf.js