-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender_report.php
39 lines (32 loc) · 1023 Bytes
/
render_report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
use Carboneio\SDK\Carbone;
/** Get your API key on your Carbone account: https://account.carbone.io/. **/
$carbone = new Carbone('PRIVATE_API_KEY');
/** Template ID */
$templateId = "b0126ca004a93dd78c85cbeafb15dd3b9d64ce728c04712adea195c93681ceff";
/**
* Rendering options:
* - "data" is required and contains all data injected inside the document
* - "convertTo" defines the export format
* - More options: https://carbone.io/api-reference.html#render-reports
*/
$data = [
"data" => [
"firstname" => "John Wick"
],
"convertTo" => "pdf"
];
/** Generate the document */
$response = $carbone->renders()->render($templateId, $data);
$result = $response->json();
echo "Request Status Code: " . $response->status() . "\n";
/** Handle errors */
if ($result['success'] == false) {
echo "Something went wrong: " . $result['error'] . "\n";
} else {
/**
* Success, save the render ID:
* The render ID is a unique id to download a the generate document
*/
echo $response->getRenderId();
}