<iframe width="100%" height="100%" src="" frameborder="0" id="iframe">iframe>
使用方法:
直接调用就行
viewPdf('传入base64编码即可')
const viewPdf =(content:any)=> {
const blob = base64ToBlob(content);
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob);
} else {
let iframe = document.getElementById("iframe")
if(iframe){
iframe.src= URL.createObjectURL(blob);
}
}
}
const base64ToBlob = (code:any)=> {
code = code.replace(/[\n\r]/g, '');
const raw = window.atob(code);
const rawLength = raw.length;
const uInt8Array = new Uint8Array(rawLength);
for (let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], { type: 'application/pdf' });
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32