LogoDOCS
OverviewAuthenticationRate LimitsErrors
Logo
Sign in →

Java SDK

The Java SDK provides a client for integrating PDFGate API endpoints into your applications.

Source code: github.com/pdfgate/pdfgate-sdk-java
Package: central.sonatype.com/artifact/com.pdfgate/pdfgate

Installation

The SDK is published to Maven Central under com.pdfgate:pdfgate. Add the dependency to Gradle or Maven, then initialize the client with your API key.

Gradle
1implementation "com.pdfgate:pdfgate:0.1.0"
Maven
1<dependency>2    <groupId>com.pdfgate</groupId>3    <artifactId>pdfgate</artifactId>4    <version>0.1.0</version>5</dependency>

Quick start

The example below generates a PDF from HTML, retrieves the stored file bytes, and writes the output to disk.

1import com.pdfgate.GeneratePdfParams;2import com.pdfgate.GetFileParams;3import com.pdfgate.PdfGate;4import com.pdfgate.PdfGateDocument;5import java.io.IOException;6import java.nio.file.Files;7import java.nio.file.Path;8import java.nio.file.Paths;910public class PdfGateExample {11  static void main(String[] args) {12    String apiKey = "test_123";13    PdfGate client = new PdfGate(apiKey);1415    try {16      GeneratePdfParams params = GeneratePdfParams.builder()17          .html("<html><body><h1>Hello, PDFGate!</h1></body></html>")18          .build();1920      PdfGateDocument document = client.generatePdf(params);2122      Path filePath = Paths.get("output.pdf");23      byte[] fileBytes = client.getFile(GetFileParams.builder()24          .documentId(document.getId())25          .build());26      Files.write(filePath, fileBytes);27    } catch (IOException e) {28      System.err.println("Error writing to file: " + e.getMessage());29    }30  }31}

Sync and async usage

The SDK exposes synchronous methods, Async variants based on CompletableFuture, and callback-style methods with a Call suffix.

1PdfGateDocument document = client.generatePdf(params);23CompletableFuture<PdfGateDocument> pdfFileFuture = client.generatePdfAsync(params);45CallJson call = client.generatePdfCall(params);

Core methods

MethodPurpose
generatePdfGenerate a PDF from HTML or a URL.
getDocumentRetrieve document metadata and processing details.
getFileDownload the stored PDF bytes for a document id.
uploadFileUpload a PDF from bytes or by public URL.
flattenPdfFlatten form fields into a non-editable document.
compressPdfCompress a PDF and return the resulting document record.
watermarkPdfApply an image or text watermark to a PDF.
protectPdfEncrypt a PDF and apply access restrictions.
extractPdfFormDataRead submitted values from fillable PDF forms.

Related documentation

Use the SDK together with the main API documentation for endpoint behavior, request parameters, and workflow guides such as webhooks and PDF form fields.