Created
November 29, 2018 14:55
-
-
Save ClementParis016/4354d3c0c9c3011841f350730604737d to your computer and use it in GitHub Desktop.
Render raw binary PDF data in a PDF viewer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Originally tweeted at https://twitter.com/ClementParis016/status/1065000952749539329 | |
// Fetch raw binary PDF data | |
const response = await fetch('https://some.pdf'); | |
// Extract response body as Blob | |
const blob = await response.blob(); | |
// Create an URL pointing to the object | |
const url = URL.createObjectURL(blob); | |
// Render a PDF viewer! | |
<object data={url} type="application/pdf"></object> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment