I am using PHP SDK for docusign integration in laravel. I am trying to download signed document envelop in my public folder. I am getting the PDF content after following the steps. But when i tried to save it in PDF file using file_put_contents then its save a PDF file but after opening it gives me PDF document is damaged.
$ch = curl_init();
$headers = array(
'Content-Type: application/pdf',
'Authorization: Bearer '.$_SESSION['docusign_auth_code']
);
curl_setopt($ch, CURLOPT_URL, 'https://demo.docusign.net/restapi/v2/accounts/{account_id}/envelopes/{envelop_id}/documents/1/');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$file_content = curl_exec($ch);
file_put_contents("my_document.pdf", ($file_content));
return $file_content;
I have tried above code and this code is working but PDF file is giving error on opening.
See Send file to the user for more details, here is PHP code that we have in https://github.com/docusign/code-examples-php/blob/master/src/Controllers/Examples/eSignature/EG007EnvelopeGetDoc.php for this: