E
E
Eugene2016-02-05 18:58:30
PHP
Eugene, 2016-02-05 18:58:30

How to display received PDF stream by curl?

Tell me this question, I work with the API of one delivery company. The API structure is implemented according to the REST architecture. Communication is done through JSON messages.
In some requests, I receive response data in the form of an array, there are no problems with this. And some "contain a stream with a pdf file as an array of bytes (begins with "%PDF")".

$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_URL, "http://sierra.pickpoint.ru/api/".$type);
curl_setopt($curl, CURLOPT_POST, $postType);
if($postType) curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($request));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl);
curl_close($curl);
if($data === false)	return false;
return $data;

How do I properly work with the resulting/generated PDF file. How can I just output it to the browser (without saving it to a file)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maximw, 2016-02-05
@atachrus

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
echo $data;

A
Andrey, 2016-02-05
@VladimirAndreev

display the headers with which the pdf file is given, then
echo $data; die;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question