New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we pass the base 64 blob? #85
Labels
documentation
Improvements or additions to documentation
Comments
It's possible @rchancey (as you see it supports opening a local file). |
@rchancey
const base64toBlob = (b64Data, contentType='', sliceSize=512) => {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, {type: contentType});
return blob;
}
const blob = base64toBlob(b64Data, contentType);
const blobUrl = URL.createObjectURL(blob);
<Viewer fileUrl={blobUrl} /> |
This was referenced Mar 29, 2020
Here's the live example: https://react-pdf-viewer.dev/examples/preview-a-pdf-file-from-base-64 |
Done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we use the actual pdf data blob rather than a URL?
The text was updated successfully, but these errors were encountered: