Developer Guide

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

1

Installation

Add the TurboDocx SDK to your project using Maven or Gradle.

pom.xml (Maven)
<dependency>
    <groupId>com.turbodocx</groupId>
    <artifactId>turbodocx-sdk</artifactId>
    <version>0.1.4</version>
</dependency>
build.gradle (Gradle)
implementation 'com.turbodocx:turbodocx-sdk:0.1.4'

Requirements: Java 11+. Compatible with Spring Boot, Quarkus, and other frameworks.

2

Obtaining an API Key

Before you begin, you'll need your API credentials from the TurboDocx dashboard.

  1. Sign up for a free account at TurboDocx
  2. Navigate to Settings → API Keys
  3. Copy your API Key and Organization ID
application.properties (Spring Boot)
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 Name
3

Sending a Signing Request

Use the SDK to send a document for signature. The recipient will receive an email with a link to sign.

Main.java
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 FieldTemplate.Builder()
                            .anchor("{signature1}")
                            .placement("replace")
                            .size(new FieldSize(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.

4

Processing Results with Webhooks

Configure webhooks to receive real-time notifications when documents are signed.

WebhookController.java (Spring Boot)
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);
    }
}
5

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

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.