How do I display a PDF that is getting returned from an api?

Viewed 497

I'm working on a JavaScript/React project and I have a GET endpoint that when I hit returns back a PDF. I am able to hit the endpoint successfully and am getting back a 200 success back but the response I'm getting back looks like something along the lines of....

%PDF-1.4 1 0 obj << /Title (��) /Creator(��) /Producer(��)....

Does anyone know how I can take this and turn it into the PDF file in a separate window or popup? All the solutions I have found are requiring me to have a pdf url or file to do this. I'm completely new to this and would really appreciate some help.

3 Answers

If you set the return content type to "application/pdf", your browser should display it correctly I think. How you set the content type depends on what you're using server side.

I think you should try to send your PDF file from the endpoint as base64 URI so you can Download the file or just open it in your browser, your API should respond something link this :

echo "data:application/pdf;base64,".base64_encode($YourFileHere);
Related