承接 templatefox/sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

Packagist Version License: MIT

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

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 templatefox/sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-05