1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Support downloading PDF through the API

This commit is contained in:
Hillel Coren 2016-06-01 12:56:59 +03:00
parent 1760d0e0e4
commit e08e8c1962
2 changed files with 19 additions and 5 deletions

View File

@ -358,4 +358,17 @@ class InvoiceApiController extends BaseAPIController
return $this->itemResponse($invoice);
}
public function download(InvoiceRequest $request)
{
$invoice = $request->entity();
$pdfString = $invoice->getPDFString();
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($pdfString));
header('Content-disposition: attachment; filename="' . $invoice->getFileName() . '"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
return $pdfString;
}
}

View File

@ -255,6 +255,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
//Route::get('quotes', 'QuoteApiController@index');
//Route::resource('quotes', 'QuoteApiController');
Route::get('invoices', 'InvoiceApiController@index');
Route::get('download/{invoice_id}', 'InvoiceApiController@download');
Route::resource('invoices', 'InvoiceApiController');
Route::get('payments', 'PaymentApiController@index');
Route::resource('payments', 'PaymentApiController');