This repository demonstrates how to implement a "Save As" feature to convert an edited DOCX file into PDF or HTML using GroupDocs Editor for Java.
Developers often need to load, edit, and export Word documents in Java applications — especially when building document collaboration or reporting systems. GroupDocs Editor for Java provides a unified API to load, edit, and convert documents like DOCX, XLSX, and others — including the ability to export edited content to PDF or HTML formats.
A single method — saveDocxAsPdfAndHtml(...) — walks through the full workflow:
- Load a DOCX document using
WordProcessingLoadOptions. - Edit the document (change a heading, fill text with a highlight color).
- Save as the edited document to PDF (
PdfSaveOptions) and to HTML.
The result is a clean, production-ready Java workflow for editing and converting Word documents.
GroupDocs Editor turns a document into an editable HTML representation. Your
application (or a rich-text editor in the browser) modifies that HTML, and the
edited content is exported to the target formats. saveDocxAsPdfAndHtml(...)
applies two typical user edits before saving:
- Change a heading — rename
About GroupDocs.Editorand recolor it dark red. - Fill text with color — highlight a sentence with a yellow background (like a marker).
Editor editor = new Editor("resources/input/input.docx", new WordProcessingLoadOptions());
// Load: get the editable HTML representation.
EditableDocument original = editor.edit(new WordProcessingEditOptions());
// Edit: modify the HTML markup, then rebuild an editable document.
String editedHtml = original.getContent()
.replace("About GroupDocs.Editor",
"<span style=\"color:#C00000;\">About GroupDocs.Editor (Edited)</span>")
.replace("GroupDocs makes it straightforward to automate document processing pipelines",
"<span style=\"background-color:#FFFF00;font-weight:bold;\">…</span>");
EditableDocument edited = EditableDocument.fromMarkup(editedHtml, original.getAllResources());
// Save as: export the edited document to PDF and HTML.
editor.save(edited, "resources/output/output.pdf", new PdfSaveOptions());
edited.save("resources/output/output.html");Running the example produces two files in resources/output/:
output.pdf and output.html — the edited document (recolored heading + highlighted text).
- Java 8 or higher
- Maven 3.x
- A real DOCX file placed in
resources/input/(e.g.,input.docx)
To remove evaluation mode limitations, obtain a temporary license:
🔗 Get a free temporary license
Place the license file (e.g., GroupDocs.Editor.Java.lic) in the project root directory.
-
Clone or download this repository.
-
Place your input DOCX file at
resources/input/input.docx. -
Build and run with a single command (the main class is preconfigured in
pom.xml):mvn compile exec:java
Or run directly from your IDE after setting up the project.
-
Output files are saved in
resources/output/:output.pdf,output.html— the edited document (recolored heading + highlighted text)
# A sample input.docx is already included in resources/input/.
# To use your own document, replace it:
cp /path/to/your/document.docx resources/input/input.docx
# Build and run (one command)
mvn compile exec:javaproject-root/
├── pom.xml
├── src/
│ └── main/
│ └── java/
│ └── com/
│ └── groupdocs/
│ └── editor/
│ └── examples/
│ └── SaveEditedDocxAsPdfOrHtmlExample.java
└── resources/
├── input/ # Place your input DOCX here
└── output/ # Generated PDF/HTML files appear here
- Loading DOCX documents with
WordProcessingLoadOptions - Editing document markup via
Editor.edit()/EditableDocument.getContent()/EditableDocument.fromMarkup() - Changing a heading and highlighting text with a color fill
- Exporting the edited document to PDF using
PdfSaveOptions - Exporting the edited document to HTML from an
EditableDocument - Using the
Editorclass for document editing and conversion - License setup for GroupDocs Editor for Java
Q: Does GroupDocs Editor for Java support editing DOCX in-memory?
A: Yes. While this example focuses on load-and-convert, GroupDocs Editor supports loading documents into editable formats (e.g., HTML) for in-memory editing before saving back to DOCX or exporting to PDF/HTML.
Q: Can I convert to other formats like XLSX or RTF?
A: Yes. GroupDocs Editor supports multiple input and output formats. Check the official documentation for full format support.
Q: What happens if I don’t provide a license file?
A: The library runs in evaluation mode — watermarks are added, and some features may be limited. For production use, apply a valid license.