madebybob/carbone-sdk

0.2.0 2023-01-03 00:44 UTC

This package is auto-updated.

Last update: 2024-08-30 01:39:42 UTC


README

此软件包提供了Carbone.io API的PHP SDK。

Cover

关于Carbone

Carbone是一个功能强大且易于使用的API,可以将模板中的文档转换为PDF。它基于LibreOffice,可以转换LibreOffice支持的所有文档。还可以将HTML转换为PDF。

安装

您可以通过Composer安装绑定。运行以下命令

composer require madebybob/carbone-sdk

用法

Carbone实例

使用SDK非常简单。您只需要创建Carbone类的新的实例,并传入您的API密钥。

use MadeByBob\Carbone\Carbone;

$carbone = new Carbone('YOUR_API_KEY');

模板

上传模板

您可以使用upload方法将模板上传到Carbone。此方法将模板内容作为参数。

$response = $carbone->templates()->upload($content);

$templateId = $response->getTemplateId();

删除模板

您可以使用delete方法删除模板。此方法将模板ID作为参数。

$response = $carbone->templates()->delete($templateId);

渲染

渲染模板

您可以使用render方法渲染模板。此方法将模板ID和数据作为参数。

$response = $carbone->renders()->render($templateId, $data);

$renderId = $response->getRenderId();

下载渲染后的模板

您可以使用download方法下载渲染后的模板。此方法将渲染ID作为参数。

$response = $carbone->renders()->download($renderId);

// Save the contents of the file yourself on your filesystem
$content = $response->getContent();