Translate Word, PDF, Web documents in Java

Java solution for translating documents using AI

Seamless integration with Google Gemini generative language models provides extensive AI-based document processing capabilities for Java applications.

View code snippet

Translate Documents to 300+ Languages in Java

Automate document translation using Google Gemini AI models with Aspose.Words for Java. Translate DOC, DOCX, RTF, PDF, HTML, Markdown, ODT, TXT, and EPUB files into over 300 languages while preserving the original layout and formatting. The AI-based engine detects the source language automatically — even in multi-language documents — and leaves untranslated only those fragments it cannot identify.

Why Developers Choose Aspose.Words for Document Translation

  • Single API call to translate an entire document
  • Automatic source-language detection for mixed-language documents
  • Output preserved in the original format and layout
  • Support for DOC, DOCX, RTF, PDF, ODT, HTML, Markdown, TXT, EPUB, and more

Authentication requires a Google API key. For a full list of supported AI models, see the API Reference.

Start translating documents in Java today — try the live demo above.

Example code in Java for translating a document
Select the target format from the list
Run code
// Repository path: https://releases.aspose.com/java/repo/
// Maven, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency>
  <groupId>com.aspose</groupId>
  <artifactId>aspose-words</artifactId>
  <version>ver</version>
  <classifier>jdk17</classifier>
</dependency>
Copy
// Repository path: https://releases.aspose.com/java/repo/
// Gradle, where 'ver' - Aspose.Words version number, for example, 24.4.
compile(group: 'com.aspose', name: 'aspose-words', version: 'ver', classifier: 'jdk17')
Copy
// Repository path: https://releases.aspose.com/java/repo/
// Ivy, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency org="com.aspose" name="aspose-words" rev="ver">
 <artifact name="aspose-words" m:classifier="jdk17" ext="jar"/>
</dependency>
Copy
// Repository path: https://releases.aspose.com/java/repo/
// Sbt, where 'ver' - Aspose.Words version number, for example, 24.4.
libraryDependencies += "com.aspose" % "aspose-words" % "ver"
Copy
Document doc = new Document("Document.docx");
String apiKey = System.getenv("API_KEY");

// Use Google generative language models.
AiModel model = AiModel.create(AiModelType.GEMINI_FLASH_LATEST).withApiKey(apiKey);

Document translatedDoc = model.translate(doc, Language.ARABIC);
translatedDoc.save("Output.docx")
Document doc = new Document("Document.docx");
// Pass an empty string if the self-hosted model does not require an API key.
AiModel model = new CustomAiModel().withApiKey("");

Document translatedDoc = model.translate(doc, Language.Arabic);
translatedDoc.save("Output.docx")

static class CustomAiModel extends OpenAiModel
{
    protected String getUrl() { return "https://your-server.com/v1"; }
    protected String getName() { return "my-model-24b"; }
}
Run code

How to translate a document in Java

  1. Install Aspose.Words for Java.
  2. Add a library reference (import the library) to your Java project.
  3. Open the source file in Java.
  4. Invoke Translate method, passing in your document along with the target Language.
  5. Once completed, you will receive a translated document that you can save as a new file in the format you need.

Java library to translate documents

We host our Java packages in Maven repositories. 'Aspose.Words for Java' is a common JAR file containing byte-code. Please follow the step-by-step instructions on how to install it to your Java developer environment.

System Requirements

Java SE 7 and more recent Java versions are supported. We also provide a separate package for Java SE 6 in case you are obliged to use this outdated JRE.

Our Java package is cross-platform and runs on all operating systems with JVM implementation, including Microsoft Windows, Linux, macOS, Android and iOS.

For information on optional package dependencies, such as JogAmp JOGL, Harfbuzz font engine, Java Advanced Imaging JAI, please refer to Product Documentation.

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2026. All Rights Reserved.