Getting console erros on loading pdf file in webviewer using blob of byte array getting from Asp.net core web Api.
I want to load pdf file into Webviewer control using javascript, I tried so many ways to load document but getting console error listed below:
it is some information printed on console
1. Build: “OS85LzIwMjF8NTU4Zjg4N2Fk”
2. Core version: “8.1.0”
3. Full API: false
4. UI version: “8.1.0”
5. WebViewer Server: false
Error
Download Failed lean/PDFNetCWasm.gz.wasm
Uncaught (in promise) Download Failed lean/PDFNetCWasm.wasm
I have an Asp.net core Web API which returned file data into byte array. API Retruns
File(bytes, “application/pdf”);
In web app the code is:
var data = JSON.stringify({
"params1": 1,
"params2": 2931695,
"params3": 80430
});
var xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
xhr.onload = (event) => {
const arrayBuffer = xhr.response; // Note: not req.responseText
var base64 = btoa(
new Uint8Array(arrayBuffer)
.reduce((data, byte) => data + String.fromCharCode(byte), '')
);
debugger
WebViewer({ path: "../../../js/lib/PdfTronImage/",
enableMeasurement: true}
,document.getElementById("viewer")
).then(instance => {
// `myBase64String` is your base64 data which can come
// from sources such as a server or the filesystem
instance.UI.loadDocument(base64ToBlob(base64), { filename: 'myfile.pdf' });
const { documentViewer } = instance.Core;
documentViewer.addEventListener('documentLoaded', () => {
// perform document operations
});
});
};
xhr.open("POST", "https://MyserverDomain/api/PDFService/GetPdf");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
function base64ToBlob(base64) {
const binaryString = window.atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; ++i) {
bytes[i] = binaryString.charCodeAt(i);
}
return new Blob([bytes], { type: 'application/pdf' });
};
Note:If I tried to load pdf using PDfObject with CDN then it is loaded successfully.
What more i have to do or what wrong I did?
Note : It is not issue with byte array if i upload local pdf file to load document i got same error on local machine in devlopment environment (localhost).