How to Sign PDFs with Java
To sign a PDF with Java: Add the TurboDocx SDK to your pom.xml or build.gradle, create a client with your API key, and call client.turboSign().sendSignature() with your document and recipient details.
This guide shows you how to integrate e-signatures into your Spring Boot or Maven project in under 5 minutes.
5 min
Setup time
Java 11+
LTS support
Builder
Pattern API
Installation
Add the TurboDocx SDK to your project using Maven or Gradle.
<dependency>
<groupId>com.turbodocx</groupId>
<artifactId>turbodocx-sdk</artifactId>
<version>0.1.5</version>
</dependency>implementation 'com.turbodocx:turbodocx-sdk:0.1.5'Requirements: Java 11+. Compatible with Spring Boot, Quarkus, and other frameworks.
Obtaining an API Key
Before you begin, you'll need your API credentials from the TurboDocx dashboard.
- Sign up for a free account at TurboDocx
- Navigate to Settings → API Keys
- Copy your API Key and Organization ID
turbodocx.api-key=your_api_key_here
turbodocx.org-id=your_org_id_here
turbodocx.sender-email=you@company.com
turbodocx.sender-name=Your Company NameSending a Signing Request
Use the SDK to send a document for signature. The recipient will receive an email with a link to sign.
import com.turbodocx.TurboDocxClient;
import com.turbodocx.models.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws Exception {
// Create client with sender configuration
TurboDocxClient client = new TurboDocxClient.Builder()
.apiKey(System.getenv("TURBODOCX_API_KEY")) // REQUIRED
.orgId(System.getenv("TURBODOCX_ORG_ID")) // REQUIRED
.senderEmail(System.getenv("TURBODOCX_SENDER_EMAIL")) // REQUIRED
.senderName(System.getenv("TURBODOCX_SENDER_NAME")) // Recommended
.build();
// Read PDF file
byte[] pdfFile = Files.readAllBytes(Paths.get("contract.pdf"));
// Send document for signature
SendSignatureResponse result = client.turboSign().sendSignature(
new SendSignatureRequest.Builder()
.file(pdfFile)
.fileName("contract.pdf")
.documentName("Partnership Agreement")
.recipients(Arrays.asList(
new Recipient("John Doe", "john@example.com", 1)
)))
.fields(Arrays.asList(
new Field.Builder()
.type("signature")
.recipientEmail("john@example.com")
.template(new Field.TemplateAnchor.Builder()
.anchor("{signature1}")
.placement("replace")
.size(new Field.Size(100, 30))
.build())
.build()
)))
.build()
);
System.out.println("Document ID: " + result.getDocumentId());
}
}Builder Pattern: The SDK uses fluent builders like new Field.Builder()...build() for type-safe request construction.
Processing Results with Webhooks
Configure webhooks to receive real-time notifications when documents are signed.
import org.springframework.web.bind.annotation.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
@RestController
@RequestMapping("/webhooks")
public class WebhookController {
private final TurboDocxClient client;
@PostMapping("/turbosign")
public Map<String, Boolean> handleWebhook(@RequestBody Map<String, Object> payload) {
String eventType = (String) payload.get("event_type");
Map<String, Object> data = (Map<String, Object>) payload.get("data");
if ("document.completed".equals(eventType)) {
String documentId = (String) data.get("documentId");
try {
// Download the signed PDF
byte[] signedPdf = client.turboSign().download(documentId);
// Save to file
Files.write(
Paths.get("signed-" + documentId + ".pdf"),
signedPdf
);
} catch (Exception e) {
e.printStackTrace();
}
}
return Map.of("received", true);
}
}Conclusion
You now have everything you need to integrate document signing into your Java application. The TurboDocx SDK handles authentication, document delivery, signature collection, and provides legally-binding audit trails.
What you can do next:
- Add multiple recipients with sequential signing order
- Use different field types: initials, dates, text, checkboxes
- Integrate with Spring Security for authentication
- Get audit trails and compliance certificates
Related Guides
Sign Documents with TypeScript
Fully typed e-signature integration with imported SDK types and tsconfig setup.
Sign Documents with JavaScript
Integrate document signing into Node.js or TypeScript applications.
Sign Documents with Go
Add document signing to Go applications with idiomatic patterns.
Resources
Frequently Asked Questions
How do I sign a PDF with Java?
Add the TurboDocx SDK to your Maven/Gradle project, create a client with your API key using the Builder pattern, then use client.turboSign().sendSignature() to send the document for e-signature.
Does the Java SDK work with Spring Boot?
Yes, the TurboDocx Java SDK works with Spring Boot, Quarkus, and any Java 11+ application. It uses fluent Builder pattern for type-safe request construction.
What Java version is required?
The TurboDocx Java SDK requires Java 11 or higher (LTS versions recommended).
Ready to Get Started?
Create a free account and get your API key. Start sending documents for signature in minutes.