This package provides a PHP SDK for the Carbone.io API.
Carbone is a powerful and easy to use API to convert documents from a template to a PDF. It is based on LibreOffice and can convert any document supported by LibreOffice. It is also possible to convert HTML to PDF.
You can install the bindings via Composer. Run the following command:
composer require madebybob/carbone-sdk
Using the SDK is very easy. You just need to create a new instance of the Carbone class and provide your API key.
use MadeByBob\Carbone\Carbone;
$carbone = new Carbone('YOUR_API_KEY');
You can upload a template to Carbone using the upload
method. This method takes the contents of the template as a parameter.
$response = $carbone->templates()->upload($content);
$templateId = $response->getTemplateId();
You can delete a template using the delete
method. This method takes the template ID as a parameter.
$response = $carbone->templates()->delete($templateId);
You can render a template using the render
method. This method takes the template ID and the data as parameters.
$response = $carbone->renders()->render($templateId, $data);
$renderId = $response->getRenderId();
You can download a rendered template using the download
method. This method takes the render ID as a parameter.
$response = $carbone->renders()->download($renderId);
// Save the contents of the file yourself on your filesystem
$content = $response->getContent();