admin管理员组文章数量:1025508
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
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
Share Improve this question asked Apr 28, 2022 at 6:21 hanu saikrishnahanu saikrishna 431 gold badge2 silver badges6 bronze badges 1- Please provide enough code so others can better understand or reproduce the problem. – Community Bot Commented Apr 28, 2022 at 12:59
1 Answer
Reset to default 2Yes 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
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
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
Share Improve this question asked Apr 28, 2022 at 6:21 hanu saikrishnahanu saikrishna 431 gold badge2 silver badges6 bronze badges 1- Please provide enough code so others can better understand or reproduce the problem. – Community Bot Commented Apr 28, 2022 at 12:59
1 Answer
Reset to default 2Yes 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
本文标签:
版权声明:本文标题:javascript - How can we open a pdf file inside an angular application which was already uploaded to the same angular application 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745630968a2160161.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论