I have created a pdf file using blob text in react js and using “window.open(fileURL, “_blank”)” i am able to see the pdf in a new window.
But now my requirement is just to show the pdf as a modal in ui and when clicked on the modal it can be viewed in another window.Can anybody please help on this.
Below is my code snippet:
JavaScript
x
19
19
1
var oReq = new XMLHttpRequest();
2
3
var URLToPDF = baseUrl+"/downloadPDF
4
5
oReq.open("GET", URLToPDF, true);
6
7
oReq.responseType = "blob";
8
var that = this;
9
oReq.onload = function() {
10
11
const pdfFile = new Blob([oReq.response], { type: 'application/pdf' });
12
13
const fileURL = URL.createObjectURL(pdfFile);
14
15
window.open(fileURL, "_blank");
16
17
};
18
oReq.send();
19
Advertisement
Answer
You can add iframe with inside your modal.
JavaScript
1
6
1
<div className="modal">
2
<div className="modalContent">
3
<iframe src="http://www.africau.edu/images/default/sample.pdf" style="width:600px; height:500px;" frameborder="0"></iframe>
4
</div>
5
</div>
6