It appears you don't have Adobe-6ren">
gpt4 book ai didi

javascript - 使用 http header 预览 pdf

转载 作者:行者123 更新时间:2023-11-30 16:06:48 25 4
gpt4 key购买 nike

我正在尝试使用以下 HTML 代码在浏览器中预览 pdf:

<div class="col-xs-12 clearfix">
<object width="100%" height="600px" data="<%- model.pdf %>" type="application/pdf">
<p>It appears you don't have Adobe Reader or PDF support in this web browser. <a href="<%- model.pdf %>">Click here to download the PDF</a>. Or <a href="http://get.adobe.com/reader/" target="_blank">click here to install Adobe Reader</a>.</p>
<embed width="100%" height="600px" src="<%- model.pdf %>" type="application/pdf" />
</object>
</div>

其中 model.pdf 是我生成的从那里请求它的 url。

问题:

我正在一个完整的 javascript/fe 项目中工作,该项目是 API 的使用者。作为客户,我需要一个 token 和其他一些东西来从我必须在每次调用的 header 中设置的 API 请求数据。

所以我需要的是以某种方式在某处设置这些 header 。

我的问题:

有可能吗?

提前致谢。

最佳答案

也许 PDF.js对你有用。

The object structure of PDF.js loosely follows the structure of anactual PDF. At the top level there is a document object. From thedocument, more information and individual pages can be fetched. To getthe document:

PDFJS.getDocument('helloworld.pdf')

对于标题试试这个:

var 
obj = {};

obj.url = 'url_to_your_file.pdf';
obj.httpHeaders = {

"X-Header": "VALUE"
};

PDFJS.getDocument(obj).then(function(pdf) {

// your code
});

您阅读了有关 DocumentInitParameters 的更多信息 here .

关于javascript - 使用 http header 预览 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36932266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com