0

I am getting a response from an external api which contains an array of bytes I'd like to convert to pdf.

Sample response from the api.

So far, I have tried below code in laravel with no success.

$data is received from api.

return response($data)
                ->withHeaders([
                    'Content-Type'=> 'application/pdf'
                ]);
1
  • You can try getContent() method if you are using guzzle Commented Jul 27, 2018 at 12:49

1 Answer 1

2

The trick is to set the Content-Disposition header to force a download.

return response($data, 200, [
    'Content-type'        => 'application/pdf',
    'Content-Disposition' => 'attachment; filename="api.pdf"',
]);

You could also replace attachment with inline to render the pdf in the browser (most modern browser support this).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.