This showcase project demonstrates how to edit a DOCX document completely in memory using GroupDocs.Editor for Java 26.1. The example loads a DOCX file, replaces a piece of text (Hello → Hi) and saves the edited document without ever persisting intermediate data to disk.
project-root/
├─ pom.xml
├─ src/
│ └─ main/java/com/groupdocs/editor/examples/EditDocxInMemoryExample.java
├─ resources/
│ ├─ input/
│ │ └─ sample.docx (replace with your own DOCX)
│ └─ output/ (generated files will appear here)
└─ GroupDocs.Editor.lic (optional – place your license file here)
- Java 8 (or higher)
- Maven 3.6+
- Internet access for Maven to download the GroupDocs repository
GroupDocs library requires a license. You can obtain a free 30‑day temporary license:
- Visit: https://purchase.groupdocs.com/temporary-license/
- Download the license file (e.g.,
GroupDocs.Editor.lic). - Place the license file in the project root (same level as
pom.xml).
Without a license the library runs in evaluation mode, adding watermarks and some usage limitations.
- Clone / download the project
git clone https://github.com/your-repo/groupdocs-editor-java-edit-docx-in-memory.git cd groupdocs-editor-java-edit-docx-in-memory - Add your license file (optional but recommended) – copy
GroupDocs.Editor.licinto the project root. - Place a DOCX file you want to edit into
resources/input/and rename it tosample.docx(or replace the existing placeholder). - Build the project
mvn clean compile
- Run the example
mvn exec:java
- Loads
resources/input/sample.docxvia anInputStream. - Creates a
Editorinstance with defaultLoadOptions. - Performs an in‑memory text replacement (
Hello→Hi). - Saves the edited document to
resources/output/edited_sample.docxusing anOutputStream. - All operations stay in memory; only the final file is written to disk.
- Change the text to replace – modify the
TextReplacerparameters inEditDocxInMemoryExample.java. - Add more complex edits – explore other editing elements offered by GroupDocs.Editor such as
ParagraphReplacer,ImageReplacer, etc. - Work with other formats – GroupDocs.Editor supports DOC, DOCX, ODT, RTF, and more. Adjust the input file accordingly.
- The sample
sample.docxincluded in the repository is only a placeholder. Replace it with a real DOCX to see the actual editing effect. - Ensure the
resources/output/directory is writable; the code will create it automatically if missing. - This project is intended purely as a showcase. For production use, add robust error handling, logging, and resource management as required.
Happy coding with GroupDocs!