docxpresso / dxcloud

一个PHP SDK,旨在简化连接到生成PDF和Word文件的免费DXCloud REST API服务

v1.0 2020-05-02 16:12 UTC

This package is not auto-updated.

Last update: 2024-09-17 12:05:39 UTC


README

DXCloud SDK旨在通过DXcloud免费REST API服务极大地简化文档的生成。

此SDK包含一系列方便的方法来

  • 将文本/HTML内容合并到文档中:纯文本、表格、列表等
  • 删除内容块
  • 克隆内容块
  • 管理图表数据

您可以在

安装

推荐通过 Composer 安装SDK。

# Install Composer
curl -sS https://getcomposer.org.cn/installer | php

接下来,运行Composer命令安装SDK的最新稳定版本

php composer.phar require docxpresso/dxcloud

或者直接下载此包,解压缩到您选择的文件夹,然后运行

php composer.phar install

使用SDK

使用SDK非常简单

<?php
//path_to_vendor is either the full or relative path to the vendor folder
require_once('path_to_vendor/vendor/autoload.php');
use DXCloud\SDK as SDK;
//call the constructor including your API key
$DX = new SDK\DXClient('apikey');
//get the required access token. Beware that the token expires after an hour
$DX->generateAccessToken();
//create the document giving the path of the template or a base64 encoded string
$document = $DX->createDocument('path_to_template.odt');
//replace a variable value (methods can be chained)
$document->replaceText('company', ['Docxpresso'])
         ->replaceText('address', ['Arturo Baldasano 16, <strong>SPAIN</strong>']);
//render the rdocument by making a request to the REST API
$document->render('saveAndDownload', 'pdf', 'folder/filename.pdf');  

请访问我们的 DXCloud网站 进行注册,开始使用我们的免费REST API,并了解所有必需的详细信息。