Java
Official Java SDK for TemplateFox.
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:
| Class | Method | Description |
|---|---|---|
PDFApi | createPdf | Generate a PDF from a template |
TemplatesApi | listTemplates | List all templates in your team |
TemplatesApi | getTemplateFields | Get data fields for a template |
AccountApi | getAccount | Get account info and credit balance |
AccountApi | listTransactions | List credit transaction history |
IntegrationsApi | saveS3Config | Configure S3 storage integration |
IntegrationsApi | getS3Config | Get current S3 configuration |
IntegrationsApi | deleteS3Config | Remove S3 configuration |
IntegrationsApi | testS3Connection | Test 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