I am trying to serve a PDF file to the user, and I have a string containing the bytes in the PDF file. I want to write these bytes to the browser so the user can download the PDF file. However when I do this:
document.open('application/pdf');
document.write(myBytes);
I just get the bytes rendered as text, that is, they are in an HTML page (see screenshots). I want only the bytes specified to be rendered, without any HTML surrounding them. How can I do this?



documentrepresents, an HTML document—but PDF is not HTML. See Józef's answer for a way to do it.