浏览我们的产品

If so you can download any of the below versions for testing. The product will function as normal except for an evaluation limitation. At the time of purchase we provide a license file via email that will allow the product to work in its full capacity. If you would also like an evaluation license to test without any restrictions for 30 days, please follow the directions provided here.


Product Docs Swagger Examples Blog Support Dashboard

安装

该软件包在Packagist可用,可以通过执行以下命令通过 Composer 安装:

composer require groupdocscloud/groupdocs-assembly-cloud

Packagist Version Packagist Downloads PHP-GroupDocsCloud


要求

  • PHP 5.5 或更高版本
  • Composer
  • PHP 扩展 — curl, json, mbstring
  • GroupDocs Cloud 凭证 — Client ID and Client Secret,来自仪表板

依赖关系

SDK需要以下软件包:

PackageConstraint
guzzlehttp/guzzle^6.2
ext-curl*
ext-json*
ext-mbstring*

快速入门

获取您的 API 凭证

要使用GroupDocs.Assembly Cloud,请在GroupDocs.Cloud Dashboard注册并获取您的Client ID和Client Secret。

初始化API

使用以下代码开始使用GroupDocs.Assembly Cloud SDK for PHP:

<?php

require_once(__DIR__ . '/vendor/autoload.php');

// Get your ClientId and ClientSecret at https://dashboard.groupdocs.cloud
$assembly = new GroupDocs\Assembly\AssemblyApi("YourClientId", "YourClientSecret");
$assembly->getConfig()->setHost("https://api.groupdocs.cloud");

更多详情请参阅 BaseTestContext.php。

从模板组装文档

初始化后,使用此基本示例根据已存储在 GroupDocs Cloud 中的模板和本地数据文件生成文档。

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use GroupDocs\Assembly\Model;
use GroupDocs\Assembly\Model\Requests;

$assembly = new GroupDocs\Assembly\AssemblyApi("YourClientId", "YourClientSecret");
$assembly->getConfig()->setHost("https://api.groupdocs.cloud");

$reportData = file_get_contents("FileWithData");
$assembleData = new Model\AssembleOptions(array(
    "template_file_info" => new Model\TemplateFileInfo(array("file_path" => "FileNameInStorage")),
    "save_format" => "pdf",
    "report_data" => $reportData
));
$request = new Requests\AssembleDocumentRequest($assembleData);
$result = $assembly->assembleDocument($request);

echo "Assembled document size: " . $result->getSize() . "\n";

更多详情请参阅 SDK README。

上传模板并组装为 PDF

此示例上传TableFeatures.odt,使用TableData.json对其进行组装,并检查结果大小。

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use GroupDocs\Assembly\Model;
use GroupDocs\Assembly\Model\Requests;

$assembly = new GroupDocs\Assembly\AssemblyApi("YourClientId", "YourClientSecret");
$assembly->getConfig()->setHost("https://api.groupdocs.cloud");

$file = __DIR__ . "/TableFeatures.odt";
$remotePath = "Temp/SdkTests/php/GroupDocs/Assembly/TableFeatures.odt";

$assembly->uploadFile(new Requests\UploadFileRequest($file, $remotePath));

$reportData = file_get_contents(__DIR__ . "/TableData.json");
$assembleData = new Model\AssembleOptions(array(
    "template_file_info" => new Model\TemplateFileInfo(array("file_path" => $remotePath)),
    "save_format" => "pdf",
    "report_data" => $reportData
));
$request = new Requests\AssembleDocumentRequest($assembleData);
$result = $assembly->assembleDocument($request);

echo "Assembled document size: " . $result->getSize() . "\n";

更多详情请参阅 AssemblyApiTests.php。

获取支持的文件格式

检索支持的组装文件格式。

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use GroupDocs\Assembly\Model\Requests;

$assembly = new GroupDocs\Assembly\AssemblyApi("YourClientId", "YourClientSecret");
$assembly->getConfig()->setHost("https://api.groupdocs.cloud");

$response = $assembly->getSupportedFileFormats(new Requests\GetSupportedFileFormatsRequest());

foreach ($response->getFileFormats()->getFormats() as $format) {
    echo $format->getFileFormat() . " - " . $format->getExtension() . "\n";
}

更多详情请参阅 GetSupportedFileFormatsRequest.php。

从云存储下载文件

下载先前上传到存储中的文件。

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use GroupDocs\Assembly\Model\Requests;

$assembly = new GroupDocs\Assembly\AssemblyApi("YourClientId", "YourClientSecret");
$assembly->getConfig()->setHost("https://api.groupdocs.cloud");

$request = new Requests\DownloadFileRequest("Temp/SdkTests/php/GroupDocs/Assembly/TableFeatures.odt");
$result = $assembly->downloadFile($request);

echo "Downloaded bytes: " . $result->getSize() . "\n";

更多详情请参阅 DownloadFileRequest.php。

GitHub 上的示例

GroupDocs.Assembly Cloud PHP SDK 存储库包含 README 示例和测试,涵盖:

CategoryExamples
文档组装根据存储中的模板和本地数据文件组装文档
测试上传TestData/TableFeatures.odt,并使用TestData/TableData.json将其组装为 PDF
文件和格式 API支持的文件格式、上传和下载

如何运行示例

  1. 使用composer require groupdocscloud/groupdocs-assembly-cloud安装软件包
  2. 使用require_once('vendor/autoload.php');引入 Composer 自动加载
  3. 将您的凭证放入Settings/servercreds.json
  4. 运行README中的示例用法。更多示例位于tests

欲了解更多详情,请访问Getting Started。


Product Docs Swagger Examples Blog Support Dashboard


Tags

Document Automation | PHP Cloud API | GroupDocs.Assembly Cloud | REST API | Document Generation | Template Assembly | Report Generation | Mail Merge | JSON Data | Dynamic Data Merging | PDF Generation | Cloud Storage | File Upload API | Supported File Formats | Secure API Access



 简体中文