Which product are you using?
express plus
PDF.js Express Version
8.7.0
Detailed description of issue
I am trying to load a document from base64 string. I am converting it to a blob but when the document loads I receive an error on the viewer saying " ERROR. Invalid PDF Structure" I am following the documentation and need help deciphering what I am missing.
Expected behaviour
I expect to receive a base64 image string, covert it to a blob, and be able to see it in the pdf viewer
Does your issue happen with every document, or just one?
every document
function base64ToBlob(base64) {
const parts = base64.split(';base64,')
const decodedData = window.atob(parts[1]);
const bytes = new Uint8Array(decodedData.length);
for (let i = 0; i < decodedData.length; ++i) {
bytes[i] = decodedData.charCodeAt(i);
}
return new Blob([bytes], { type: 'application/pdf' });
};
export const PdfViewer = () => {
const viewer = useRef(null)
const sampleImage = '"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4
//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="'
const imageBlob = base64ToBlob(sampleImage);
useEffect(() => {
WebViewer({
path: '/webviewer/lib'
},
viewer.current
)
.then(instance => {
instance.UI.loadDocument(imageBlob, { filename: 'myfile.pdf' });
const { documentViewer } = instance.Core;
documentViewer.addEventListener('documentLoaded', () => {
// perform document operations
});
});
}, []);
}