Copy link to clipboard
Copied
I'm using the Embedded PDF API to view/edit pdfs in my Blazor application. I first tried using a link to the share point files but ran into what I beleive is permission issues. I'm now trying to use a promise and getting the 'getMetadata request failed' error. Code snippets below. fileContents is a byte[]
window.ViewPDF = function (path, fileContent) {
//var adobeDCView = new AdobeDC.View({ clientId: "579a461bbf7e4daea9d6ea6b7e9684a2", divId: "adobe-dc-view" }); // tpud.org
var filePromise = Promise.resolve(byteToUint8Array(fileContent).buffer);
console.log(filePromise)
console.log(path)
var adobeDCView = new AdobeDC.View({ clientId: "68cd09d526f14c959632eb34b5dd0c3e", divId: "adobe-dc-view" }); // azurewebsites.net
adobeDCView.previewFile(
{
content: { promise: filePromise },
metaData: { fileName: path }
});
}
Copy link to clipboard
Copied
Are you sure the promise is returning PDF data and not something else?
Copy link to clipboard
Copied
Raymond was correct. Converting a byte[] array from c# into an Uint8Array does not produce a pdf. I ended up converting the byte[] into a base64 string in c#, then converting that to a blob on the javascript side.
C#:
var base64String = Convert.ToBase64String(bytes);
Javascript:
const base64Data = await fetch(`data:application/pdf;base64,${base64String}`)
const blob = await base64Data.blob()
var filePromise = Promise.resolve(blob.arrayBuffer())