templatefox/sdk
Composer 安装命令:
composer require templatefox/sdk
包简介
Official TemplateFox PHP SDK - Generate PDFs from HTML templates
关键字:
README 文档
README
Official PHP SDK for TemplateFox - Generate PDFs from HTML templates via API.
Installation
composer require templatefox/sdk
Requirements
- PHP 7.4 or later
- ext-curl
- ext-json
- ext-mbstring
Quick Start
<?php require_once __DIR__ . '/vendor/autoload.php'; use TemplateFox\Api\PDFApi; use TemplateFox\Configuration; use TemplateFox\Model\CreatePdfRequest; // Initialize the client $config = Configuration::getDefaultConfiguration() ->setApiKey('x-api-key', 'your-api-key'); $api = new PDFApi(null, $config); // Generate a PDF $request = new CreatePdfRequest([ 'template_id' => 'YOUR_TEMPLATE_ID', 'data' => [ 'name' => 'John Doe', 'invoice_number' => 'INV-001', 'total_amount' => 150.00, ], ]); try { $response = $api->createPdf($request); echo "PDF URL: " . $response->getUrl() . "\n"; echo "Credits remaining: " . $response->getCreditsRemaining() . "\n"; } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
Features
- Template-based PDF generation - Create templates with dynamic variables, generate PDFs with your data
- Multiple export options - Get a signed URL (default) or raw binary PDF
- S3 integration - Upload generated PDFs directly to your own S3-compatible storage
- PSR-18 compatible - Works with any PSR-18 HTTP client
API Methods
PDF Generation
$request = new CreatePdfRequest([ 'template_id' => 'TEMPLATE_ID', 'data' => ['name' => 'John Doe'], 'export_type' => 'url', // 'url' or 'binary' 'expiration' => 86400, // URL expiration in seconds 'filename' => 'invoice-001', // Custom filename ]); $response = $api->createPdf($request);
Templates
use TemplateFox\Api\TemplatesApi; $templatesApi = new TemplatesApi(null, $config); // List all templates $templates = $templatesApi->listTemplates(); foreach ($templates->getTemplates() as $template) { echo $template->getId() . ": " . $template->getName() . "\n"; } // Get template fields $fields = $templatesApi->getTemplateFields('TEMPLATE_ID'); foreach ($fields as $field) { echo $field->getKey() . ": " . $field->getType() . "\n"; }
Account
use TemplateFox\Api\AccountApi; $accountApi = new AccountApi(null, $config); // Get account info $account = $accountApi->getAccount(); echo "Credits: " . $account->getCredits() . "\n"; echo "Email: " . $account->getEmail() . "\n"; // List transactions $transactions = $accountApi->listTransactions(100, 0); foreach ($transactions->getTransactions() as $tx) { echo $tx->getTransactionType() . ": " . $tx->getCredits() . " credits\n"; }
S3 Integration
use TemplateFox\Api\IntegrationsApi; use TemplateFox\Model\S3ConfigRequest; $integrationsApi = new IntegrationsApi(null, $config); // Save S3 configuration $s3Config = new S3ConfigRequest([ 'endpoint_url' => 'https://s3.amazonaws.com', 'access_key_id' => 'AKIAIOSFODNN7EXAMPLE', 'secret_access_key' => 'your-secret-key', 'bucket_name' => 'my-pdf-bucket', 'default_prefix' => 'generated/pdfs/', ]); $integrationsApi->saveS3Config($s3Config); // Test connection $test = $integrationsApi->testS3Connection(); echo "Connection: " . ($test->getSuccess() ? "OK" : "Failed") . "\n";
Configuration
$config = Configuration::getDefaultConfiguration() ->setHost('https://api.templatefox.com') // Default API URL ->setApiKey('x-api-key', getenv('TEMPLATEFOX_API_KEY'));
Error Handling
use TemplateFox\ApiException; try { $response = $api->createPdf($request); } catch (ApiException $e) { switch ($e->getCode()) { case 402: echo "Insufficient credits\n"; break; case 403: echo "Access denied - check your API key\n"; break; case 404: echo "Template not found\n"; break; default: echo "Error: " . $e->getMessage() . "\n"; } }
Laravel Integration
// config/services.php 'templatefox' => [ 'api_key' => env('TEMPLATEFOX_API_KEY'), ], // AppServiceProvider.php use TemplateFox\Api\PDFApi; use TemplateFox\Configuration; public function register() { $this->app->singleton(PDFApi::class, function ($app) { $config = Configuration::getDefaultConfiguration() ->setApiKey('x-api-key', config('services.templatefox.api_key')); return new PDFApi(null, $config); }); }
Documentation
Support
- Email: support@templatefox.com
- Issues: GitHub Issues
License
MIT License - see LICENSE for details.
templatefox/sdk 适用场景与选型建议
templatefox/sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「template」 「pdf」 「sdk」 「invoice」 「report」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 templatefox/sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 templatefox/sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 templatefox/sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Simple ASCII output of array data
E2E Studios PHP Framework adaptation of leafsphp/blade package
Provides TCPDF integration for Symfony
Ensolab template project
A adapter for the mPDF print library
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-05