Skip to content

Latest commit

 

History

History
82 lines (68 loc) · 3.53 KB

File metadata and controls

82 lines (68 loc) · 3.53 KB

GroupDocs Editor – Edit Word Document Programmatically

Overview

This example demonstrates how to edit a Word (DOCX) document programmatically using GroupDocs.Editor for Java. The document is converted to an editable HTML representation, modified directly in Java code, and then saved back to DOCX without any UI or WYSIWYG editor.

Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Apache Maven 3.6+
  • Internet connection (to download Maven dependencies)

License

GroupDocs libraries require a license file. You can obtain a 30‑day temporary license for free:

  1. Visit: https://purchase.groupdocs.com/temporary-license/
  2. Download the license file (e.g., GroupDocs.Editor.lic).
  3. Place the license file in the project root directory (same level as pom.xml).

Without a license the library runs in evaluation mode, adding watermarks and imposing usage limits.

Project Structure

project-root/
├─ pom.xml
├─ GroupDocs.Editor.lic          # (optional) place your license here
├─ src/
│   └─ main/java/com/groupdocs/viewer/examples/EditWordDocumentProgrammaticallyExample.java
├─ resources/
│   ├─ input/
│   │   └─ sample.docx          # sample input file (replace with your own)
│   └─ output/                  # generated files will be saved here
└─ README.md
  • Input files must be placed in resources/input/.
  • Output files are written to resources/output/ (the folder will be created automatically).

Getting Started

  1. Clone the repository (or copy the files into a new directory).
    git clone <repository‑url> groupdocs-editor-java-edit-word-document-programmatically
    cd groupdocs-editor-java-edit-word-document-programmatically
  2. Place your license file (GroupDocs.Editor.lic) in the root directory (optional but recommended).
  3. Prepare the input DOCX
    • Edit resources/input/sample.docx or put your own DOCX file there.

    • This document contains:

      • The placeholder text SAMPLE DOCUMENT for programmatic replacement.
      • A paragraph Confidential to demonstrate content removal.
      • A new paragraph <p>Inserted by GroupDocs.Editor</p> will be added during editing.
    • You can replace it with your own DOCX file, but ensure:

      • It contains placeholder text (like SAMPLE DOCUMENT) if you want to see the replacement effect.
      • Any paragraph you want to remove or edit programmatically is clearly identifiable.
  • Tip: Keep the input file simple for testing purposes; formatting, images, and tables will be preserved during editing.
  1. Build the project
    mvn clean compile
  2. Run the example
    mvn exec:java

Expected Result

When you run the application:

  • The text "SAMPLE DOCUMENT" is replaced with "Updated programmatically using GroupDocs.Editor".
  • A new file named edited_sample.docx is created.
  • The document layout, fonts, and images remain unchanged.

Notes

  • The showcase uses relative paths (resources/input/, resources/output/) so it works regardless of where the project is cloned.
  • Feel free to extend the example: add more replacements, work with other document types, or use advanced EditOptions.
  • For full API reference, visit the official documentation: https://docs.groupdocs.com/editor/java/

This is a showcase project intended to illustrate a specific capability of the GroupDocs.Editor library. It is not a production‑ready application but follows Maven best practices and clean coding standards.