Skip to Content

PHP

Official PHP SDK for TemplateFox.

Packagist Version GitHub Repository 

Installation

composer require templatefox/sdk

Generate a PDF

<?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"; }

Save PDF to File

$response = $api->createPdf($request); // Download and save locally file_put_contents('invoice.pdf', file_get_contents($response->getUrl()));

Error Handling

use TemplateFox\ApiException; try { $response = $api->createPdf($request); } catch (ApiException $e) { echo "Status: " . $e->getCode() . "\n"; echo "Message: " . $e->getResponseBody() . "\n"; }

Available Methods

The SDK covers all TemplateFox API endpoints through four service classes:

ClassMethodDescription
PDFApicreatePdfGenerate a PDF from a template
TemplatesApilistTemplatesList all templates in your team
TemplatesApigetTemplateFieldsGet data fields for a template
AccountApigetAccountGet account info and credit balance
AccountApilistTransactionsList credit transaction history
IntegrationsApisaveS3ConfigConfigure S3 storage integration
IntegrationsApigetS3ConfigGet current S3 configuration
IntegrationsApideleteS3ConfigRemove S3 configuration
IntegrationsApitestS3ConnectionTest S3 bucket connectivity

Configuration

$config = Configuration::getDefaultConfiguration() ->setApiKey('x-api-key', getenv('TEMPLATEFOX_API_KEY'));

Quick Testing

Want to test the API before integrating the SDK? Use our Postman collection  to try all endpoints interactively.

Full SDK Reference

For the complete API coverage including templates, account, S3 integration, and error handling, see the GitHub repository README .

Last updated on