Check grammar of Word, PDF, Web documents in Java

Java solution for checking grammar using AI

Seamless integration with major language models such as OpenAI, Claude and Gemini provides extensive AI-based document processing capabilities for Java applications.

View code snippet

AI Grammar Checker for Documents in Java

Detect and highlight grammar errors in documents using OpenAI, Google, and Claude AI models with Aspose.Words for Java. The CheckGrammar method analyzes DOC, DOCX, RTF, PDF, HTML, Markdown, ODT, TXT, and EPUB files and marks grammatical problems — helping you deliver polished, professional content without manual proofreading.

Why Developers Choose Aspose.Words for Grammar Checking

  • One API call to grammar-check an entire document
  • Support for OpenAI (GPT-4o), Google (Gemini), and Claude model families
  • Highlighted errors in the output document for easy review
  • Support for DOC, DOCX, RTF, PDF, ODT, HTML, Markdown, TXT, EPUB, and more

Authentication requires an API key from your chosen AI provider. For a full list of supported models, see the API Reference.

Start checking grammar in Java today — try the live demo above.

Example code in Java for grammar checking
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 OpenAI generative language models.
AiModel model = AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);

CheckGrammarOptions grammarOptions = new CheckGrammarOptions();
grammarOptions.setImproveStylistics(true);

Document proofedDoc = model.checkGrammar(doc, grammarOptions);
proofedDoc.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("");

CheckGrammarOptions grammarOptions = new CheckGrammarOptions();
grammarOptions.setImproveStylistics(true);

Document proofedDoc = model.checkGrammar(doc, grammarOptions);
proofedDoc.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 check grammar in a document using 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 CheckGrammar method, passing in your document.
  5. Once completed, the grammatical issues in the document will be highlighted, and you can save the result as a new file in the format you need.

Java library to check grammar

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.