将PDF加载到JavaScript错误中,但为什么直接在浏览器中成功地将PDF成功加载

发布于 2025-01-22 18:05:02 字数 678 浏览 1 评论 0原文

全部。 我正在考虑使用PDFTRON SDK(SDK帮助加载PDF)的问题。该SDK能够加载本地PDF文件,就像魅力一样工作。我决定使用PDFTRON SDK,例如https://cdn.mendix.tencent-cloud.com/documentation/develovelerportal/tencencent-deploy.pdf',我决定在我的Web应用程序中加载一个在线PDF文件。该文件可以直接在浏览器中访问,但是当我使用脚本时,例如:

instance.UI.loadDocument('https://cdn.mendix.tencent-cloud.com/documentation/developerportal/tencent-deploy.pdf');
  };

运行应用程序时直接遇到错误,这表明

Request URL: https://cdn.mendix.tencent-cloud.com/documentation/developerportal/tencent-deploy.pdf
Request Method: HEAD
Status Code: 403 
Referrer Policy: strict-origin-when-cross-origin

我认为这是一个CORS问题。但是我不明白为什么我可以使用浏览器获取此文件,而脚本却没有。我该如何解决?谢谢

all.
I am thinking about a issue using pdfTron SDK(an SDK help load pdf) in my application. This SDK is able to load local pdf files, working like a charm. I decide to load an online pdf file in my web application, using pdfTron SDK, e.g. 'https://cdn.mendix.tencent-cloud.com/documentation/developerportal/tencent-deploy.pdf'. This file is accessible in browser, directly, but when I use scripts, like:

instance.UI.loadDocument('https://cdn.mendix.tencent-cloud.com/documentation/developerportal/tencent-deploy.pdf');
  };

I directly got an error when running the application, which shows

Request URL: https://cdn.mendix.tencent-cloud.com/documentation/developerportal/tencent-deploy.pdf
Request Method: HEAD
Status Code: 403 
Referrer Policy: strict-origin-when-cross-origin

I think this is a CORS issue. But I cannot understand why I can use browser getting this file, while scripts does not. How can I resolve this? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

め七分饶幸 2025-01-29 18:05:02

我建议阅读有关pdftron的文档,涉及“ WebView”和“ LoadDocment”。

WebView用于获取要从任何源(文件或Web)中使用的PDF,在您的情况下,您需要使用“ InitiaLdoc”属性,这就是您所在的位置。文档/developerportal/…”。

然后使用“ instance.ui.loaddocument”来识别您要放置被提取文档的HTML元素。

=/样本/查看/ https://www.pdftron.com/documentation/#api“ rel =“ nofollow noreferrer”> api docs

I would suggest to read the documentation on pdfTron concerning "webview" and "loadDocment".

WebView is used to get the pdf you want to use from any source(file or web), in your case, you need to use "initialDoc" property, that is where you would place "cdn.mendix.tencent-cloud.com/documentation/developerportal/…".

Then "instance.UI.loadDocument" is used to identify the html element where you want to place the fetched document.

Sample

API Docs

メ斷腸人バ 2025-01-29 18:05:02

我还在文档服务器(NGINX)中尝试了CORS配置,例如:

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

这可以正常工作。但是看来,如果文档服务器不是您的,您将无法执行此操作。希望这个帮助!

I also try a CORS config in my document server(nginx), like this:

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

This works now. But It seems that if the document server is not yours, you cannot do this. Hope this help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文