How to Load a PDF in a Browser Window from a PDF Byte Array

July 14, 2019

I got stuck on this seemingly easy task a couple of weeks ago. I've somehow had gone my whole career without having to do this, but I've seen it done countless times on other sites.

I think the reason why I got stuck was because I tried the most complex solutions first thinking that they're more likely to work. I was wrong. Lesson learned. Try the easiest solution first.

Here's my solution. I ended up using an embed tag and make the src attribute equal to the api endpoint that was returning the byte array.

{{CODE}}

<div class="pdf">

  <embed src="https://api_url/path/to/endpoint" type="application/pdf" />

</div>

{{ENDCODE}}

Your last step would be to style it however you want.