Skip to content

Instantly share code, notes, and snippets.

@ClementParis016
Created November 29, 2018 14:55
Show Gist options
  • Save ClementParis016/4354d3c0c9c3011841f350730604737d to your computer and use it in GitHub Desktop.
Save ClementParis016/4354d3c0c9c3011841f350730604737d to your computer and use it in GitHub Desktop.
Render raw binary PDF data in a PDF viewer
// 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