1. Products
  2.   Aspose.Words
  3.   Aspose.Words FOSS for Java

Aspose.Words FOSS for Java

Create, edit and convert Word documents from Java, with no Microsoft Word installed. Reads and writes DOCX, Markdown and plain text. MIT-licensed.

Open-Source Java Library for Word Documents

Aspose.Words FOSS for Java is an MIT-licensed Java library for creating, editing and converting Word documents. Document holds a whole document and DocumentBuilder writes content into it. DOCX, DOCM, DOTX, DOTM, four Flat OPC variants, Markdown and plain text can be loaded and saved, and no copy of Microsoft Word is needed.

The library builds documents from code, including headings, paragraphs and tables. It replaces text with Range.replace, appends one document to another with appendDocument, and accepts tracked changes with acceptAllRevisions. The API reference lists 634 public types.

This is the open-source edition. It uses the package name com.aspose.words of the commercial Aspose.Words for Java but reads and writes a smaller set of formats: saving as PDF, XPS, HTML, MHTML, EPUB, RTF, DOC, ODT, WordML or images is rejected, and so is loading HTML, ODT or RTF. It installs with a single Maven dependency (org.aspose:aspose-words-foss:26.3.0) and needs Java 8 or later.

For the enterprise product family, see Aspose.Words — Enterprise Product Family.

Documents and Text

  • Create documents: Document creates a blank document, or opens an existing file when you pass a file name.
  • Write content: DocumentBuilder keeps a cursor in the document and writeln inserts a line of text.
  • Headings and styles: set StyleIdentifier.HEADING_1 on the paragraph format before writing a heading.
  • Read text: getText returns the text of a document.

Typical Tasks

  • Generate a report with a heading and paragraphs from code.
  • Open a DOCX and read its text.
  • Save a document under a new file name.

Tables, Find and Replace

  • Tables: startTable, insertCell, endRow and endTable on DocumentBuilder build a table cell by cell.
  • Replace text: Range.replace replaces all occurrences of a string and returns the number of replacements.
  • Placeholders: open a template, replace a marker such as {{CLIENT_NAME}} and save the filled copy.

Typical Tasks

  • Fill a contract or letter template from application data.
  • Add a table to a generated report.

Conversion Between Formats

  • Read and write: DOCX, DOCM, DOTX, DOTM, Flat OPC, Markdown and plain text are loaded and saved in both directions.
  • Convert by file name: open a file with the Document constructor and save it with the file extension of the target format.
  • Rejected formats: PDF, XPS, HTML, MHTML, EPUB, RTF, DOC, ODT, WordML and image output throw an UnsupportedOperationException whose message starts with FOSS.

Typical Tasks

  • Turn a Markdown file into a DOCX.
  • Export a DOCX as Markdown or plain text.

Tracked Changes and Merging

  • Accept changes: acceptAllRevisions accepts every tracked change in a document.
  • Merge documents: appendDocument appends one document to another, and ImportFormatMode chooses how formatting is handled.

Typical Tasks

  • Finalize a reviewed document and save the clean version.
  • Combine a main document and an appendix into one file.

Create a Document and Convert a File to Markdown

Create a document with a heading and a paragraph, save it as DOCX, then open an existing document and save it as Markdown.

<dependency>
  <groupId>org.aspose</groupId>
  <artifactId>aspose-words-foss</artifactId>
  <version>26.3.0</version>
</dependency>
import com.aspose.words.*;
// Create a document from scratch.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
builder.writeln("Hello from Aspose.Words FOSS!");

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.BODY_TEXT);
builder.writeln("This document was created entirely in code, no Word installed.");

doc.save("Hello.docx");

// Convert an existing document to Markdown.
Document report = new Document("Report.docx");
report.save("Report.md");

Convert Markdown to DOCX

Pass the Markdown file name to the Document constructor and save the document with a .docx file name.

import com.aspose.words.*;
Document doc = new Document("notes.md");
doc.save("notes.docx");

Accept Tracked Changes

Open a reviewed document, accept all tracked changes and save the final version.

import com.aspose.words.*;
Document doc = new Document("reviewed.docx");
doc.acceptAllRevisions();
doc.save("final.docx");

Merge Two Documents

Append a second document to the first and keep the source formatting.

import com.aspose.words.*;
Document main = new Document("main.docx");
Document appendix = new Document("appendix.docx");
main.appendDocument(appendix, ImportFormatMode.KEEP_SOURCE_FORMATTING);
main.save("combined.docx");

Frequently Asked Questions

What is the licensing model?

Aspose.Words FOSS for Java is open-source software released under the MIT license.

Is this the same as the commercial Aspose.Words for Java?

No. It is a reduced edition that uses the same package name, com.aspose.words, but reads and writes a smaller set of formats. The commercial product is separate and has its own license.

How do I install it?

Add org.aspose:aspose-words-foss:26.3.0 to your Maven build. The library needs Java 8 or later and was run on Java 8, 17 and 21. Microsoft Word is not needed.

Which formats can I read and write?

DOCX, DOCM, DOTX, DOTM, four Flat OPC variants, Markdown and plain text were loaded and saved in both directions.

Which formats are rejected?

Saving as PDF, XPS, HTML, MHTML, EPUB, RTF, DOC, ODT, WordML, PNG, SVG or TIFF throws an UnsupportedOperationException whose message starts with FOSS. Loading HTML, ODT or RTF does the same.

Can I create digital signatures?

No. DigitalSignatureUtil.sign throws an UnsupportedOperationException whose message starts with FOSS.

  

Support and Learning Resources