Skip to main content

Java SDK

Use the official Pritset Java SDK to manage DOCX templates and generate PDFs from your Java application.

View the official Java SDK repository on GitHub

Requirementsโ€‹

  • Java 17 or newer
  • Maven 3.9 or newer
  • A Pritset access token and secret from the Profile page

The SDK uses Java's built-in HttpClient and Jackson 2.x. It is verified on Java 17, 21, and 25.

Compatibilityโ€‹

This page documents SDK version 0.1.5, which implements Pritset SDK contract 1.0.0.

Install the dependencyโ€‹

Add version 0.1.5 from Maven Central to your pom.xml:

<dependency>
<groupId>com.pritset</groupId>
<artifactId>pritset-java</artifactId>
<version>0.1.5</version>
</dependency>

Create a clientโ€‹

Store credentials in environment variables rather than source code. Pritset sends the access token directly in the Authorization header and the secret in X-Secret; do not add a Bearer prefix.

import com.pritset.sdk.PritsetClient;

PritsetClient client = PritsetClient.builder(
System.getenv("PRITSET_ACCESS_TOKEN"),
System.getenv("PRITSET_SECRET"))
.build();

PritsetClient.toString() redacts credentials. Do not commit or log either credential.

Generate a PDFโ€‹

Upload a DOCX template first and copy its ID. See Template management for upload requirements and the portal workflow.

PDF responses stream through InputStream. Always close BinaryResponse.

import com.pritset.sdk.BinaryResponse;
import java.nio.file.Path;
import java.util.Map;

Map<String, Object> data = Map.of(
"invoice", Map.of("number", "INV-1042", "customer", "Ada Lovelace"));

try (BinaryResponse pdf = client.documents().generate("YOUR_TEMPLATE_ID", data)) {
pdf.save(Path.of("invoice.pdf"));
}

To process the stream directly, use pdf.body().transferTo(destination). Response metadata is available through contentType(), contentLength(), and trace().

The data object must match the placeholders and loops in your DOCX file. See Templating syntax.

Manage templatesโ€‹

Use client.templates() to list, retrieve, create, update, download, validate, and delete templates.

import com.pritset.sdk.Upload;
import com.pritset.sdk.model.CreateTemplateRequest;
import com.pritset.sdk.model.ListTemplatesOptions;
import com.pritset.sdk.model.SortDirection;
import com.pritset.sdk.model.Template;
import com.pritset.sdk.model.TemplatePage;
import java.nio.file.Path;

TemplatePage page = client.templates().list(ListTemplatesOptions.builder()
.query("invoice")
.page(1)
.pageSize(25)
.sortBy("name")
.sortDirection(SortDirection.ASCENDING)
.build());
System.out.printf("Found %d templates%n", page.total());

Upload upload = Upload.fromPath(
Path.of("invoice.docx"),
"application/vnd.openxmlformats-officedocument.wordprocessingml.document");

Template created = client.templates().create(new CreateTemplateRequest(
"Monthly invoice",
"invoice,monthly",
upload));

Retrieve the complete template record, including file metadata, then update its name and tags. The final Upload argument is optional; provide one to replace the DOCX file.

import com.pritset.sdk.model.TemplateDetails;
import com.pritset.sdk.model.UpdateTemplateRequest;

TemplateDetails details = client.templates().get(created.id());
System.out.println(details.fileInfo().objectName() + ": " + details.fileInfo().size());

Template updated = client.templates().update(
created.id(),
new UpdateTemplateRequest(
"Monthly invoice 2026",
"invoice,monthly,2026",
Upload.fromPath(Path.of("invoice-2026.docx")))); // optional replacement file

Upload.fromPath is repeatable and opens its file only for a request. Upload.fromInputStream is single-use and, by default, leaves the caller's stream open.

import com.pritset.sdk.BinaryResponse;
import java.nio.file.Path;
import java.util.Map;

try (BinaryResponse source = client.templates().download(created.id())) {
source.save(Path.of("downloaded-invoice.docx"));
}

boolean valid = client.templates().validate(upload, Map.of(
"invoice", Map.of("number", "INV-1042")));
System.out.printf("Template valid: %s%n", valid);

client.templates().delete(created.id());

For endpoint behavior and limits, see the Template management API reference.

Raw JSONโ€‹

Pass a JSON string when data is already encoded. Invalid or trailing JSON is rejected before a request is sent.

try (BinaryResponse pdf = client.documents().generate(
"YOUR_TEMPLATE_ID",
"{\"name\":\"Ada\"}")) {
pdf.save(Path.of("invoice.pdf"));
}

Generate through a webhookโ€‹

Use generateWebhook when Pritset should send the generation result to your endpoint. The webhook URI must be an absolute HTTP(S) URI without embedded credentials or a fragment.

import com.pritset.sdk.model.WebhookJob;
import java.net.URI;

WebhookJob job = client.documents().generateWebhook(
"YOUR_TEMPLATE_ID",
data,
URI.create("https://example.com/webhooks/pritset"));

The SDK submits the URI to Pritset; it does not call the webhook itself. See Direct and webhook processing for the API workflow.

Handle errors and interruptionโ€‹

The SDK raises PritsetApiException for API responses with an error status and PritsetTransportException for timeouts, interruption, and transport failures. It does not retry automatically.

import com.pritset.sdk.exception.PritsetApiException;
import com.pritset.sdk.exception.PritsetTransportException;

try {
client.templates().get("YOUR_TEMPLATE_ID");
} catch (PritsetApiException exception) {
System.out.printf("HTTP %d; trace ID: %s%n",
exception.statusCode(), exception.traceId().orElse("not provided"));
} catch (PritsetTransportException exception) {
System.out.printf("Timed out: %s; interrupted: %s%n",
exception.isTimeout(), exception.isInterrupted());
}

Set a custom timeout when creating the client. You can cancel a blocking operation by interrupting its thread; the SDK restores the interrupt flag and reports isInterrupted().

import java.time.Duration;

PritsetClient client = PritsetClient.builder(token, secret)
.timeout(Duration.ofSeconds(90))
.build();

See API errors for status codes and retry guidance.

Local development and custom HTTP clientsโ€‹

The SDK uses https://api.pritset.com by default and disables automatic redirects on its own HTTP client. HTTP is allowed only for exact loopback development endpoints such as http://127.0.0.1:8080.

If you inject an HttpClient, you own its lifetime and must disable redirects:

import java.net.http.HttpClient;

HttpClient httpClient = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NEVER)
.build();

PritsetClient client = PritsetClient.builder(token, secret)
.httpClient(httpClient)
.build();

Next stepsโ€‹