我们如何在已经上传到同一角度应用的角度应用程序内打开PDF文件

发布于 2025-01-24 19:02:53 字数 94 浏览 3 评论 0原文

我正在开发一个角度应用程序,其中我上传了一个PDF文件。我需要在ModalWindow中的同一应用程序中打开同一PDF文件。 我尝试使用但没有用。我不应该使用任何PDF观看器

I am developing an angular application in which I uploaded a pdf file. I need to open the same pdf file onClick of it inside same application in a modalwindow.
I tried using and but no use. I should not use any pdf-viewers

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

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

发布评论

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

评论(1

沉溺在你眼里的海 2025-01-31 19:02:53

是的,您只需在新的选项卡中重新使用上传的PDF,然后将其打开:

var blob = new Blob([pdfBuffer], {type: 'application/pdf'});
var blobURL = URL.createObjectURL(blob);
window.open(blobURL);

如果您不想在新选项卡中打开它,则需要找到一个插件来显示HTML内的BLOB。或者也许是iframe。

尝试使用元素,将资源作为blob

html

<div id="my-container" class="ng-scope pdfobject-container">
    <iframe src="" type="application/pdf" width="100%" height="100%" style="overflow: auto;">
    </iframe>
</div>

javaScript

var xhr = new XMLHttpRequest();
// load `document` from `cache`
xhr.open("GET", "/path/to/file.pdf", true); 
xhr.responseType = "blob";
xhr.onload = function (e) {
    if (this.status === 200) {
        // `blob` response
        console.log(this.response);
        var file = window.URL.createObjectURL(this.response);
        document.querySelector("iframe").src = file;

    }
};
xhr.send();

- &gt;也看
使用pdfobject嵌入斑点

Yes you can just re-use your uploaded pdf like blob and open it in a new Tab:

var blob = new Blob([pdfBuffer], {type: 'application/pdf'});
var blobURL = URL.createObjectURL(blob);
window.open(blobURL);

If you don't want to open it in a new tab, you need to find a Plugin to display blob inside your html. Or maybe with iframe.

Try using element, requesting resource as a Blob

html

<div id="my-container" class="ng-scope pdfobject-container">
    <iframe src="" type="application/pdf" width="100%" height="100%" style="overflow: auto;">
    </iframe>
</div>

javascript

var xhr = new XMLHttpRequest();
// load `document` from `cache`
xhr.open("GET", "/path/to/file.pdf", true); 
xhr.responseType = "blob";
xhr.onload = function (e) {
    if (this.status === 200) {
        // `blob` response
        console.log(this.response);
        var file = window.URL.createObjectURL(this.response);
        document.querySelector("iframe").src = file;

    }
};
xhr.send();

-> Also see
Embed a Blob using PDFObject

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