Skip to Content

Java

Official Java SDK for TemplateFox.

Maven Central GitHub Repository 

Installation

Maven

<dependency> <groupId>io.github.templatefoxpdf</groupId> <artifactId>sdk</artifactId> <version>1.0.0</version> </dependency>

Gradle

implementation 'io.github.templatefoxpdf:sdk:1.0.0'

Generate a PDF

import com.templatefox.sdk.ApiClient; import com.templatefox.sdk.api.PDFApi; import com.templatefox.sdk.model.CreatePdfRequest; public class Example { public static void main(String[] args) { // Initialize the client ApiClient client = new ApiClient(); client.setApiKey("your-api-key"); PDFApi api = new PDFApi(client); // Generate a PDF CreatePdfRequest request = new CreatePdfRequest() .templateId("YOUR_TEMPLATE_ID") .putDataItem("name", "John Doe") .putDataItem("invoice_number", "INV-001") .putDataItem("total_amount", 150.00); try { var response = api.createPdf(request); System.out.println("PDF URL: " + response.getUrl()); System.out.println("Credits remaining: " + response.getCreditsRemaining()); } catch (Exception e) { e.printStackTrace(); } } }

Save PDF to File

import java.io.*; import java.net.URL; var response = api.createPdf(request); // Download and save locally try (InputStream in = new URL(response.getUrl()).openStream(); OutputStream out = new FileOutputStream("invoice.pdf")) { in.transferTo(out); }

Error Handling

import com.templatefox.sdk.ApiException; try { var response = api.createPdf(request); } catch (ApiException e) { System.err.println("Status: " + e.getCode()); System.err.println("Message: " + e.getResponseBody()); }

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

ApiClient client = new ApiClient(); client.setApiKey(System.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