Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Save Edited DOCX as PDF or HTML using GroupDocs Editor for Java

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.

Overview

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:

  1. Load a DOCX document using WordProcessingLoadOptions.
  2. Edit the document (change a heading, fill text with a highlight color).
  3. 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.

How it works

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:

  1. Change a heading — rename About GroupDocs.Editor and recolor it dark red.
  2. 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).

Prerequisites

  • Java 8 or higher
  • Maven 3.x
  • A real DOCX file placed in resources/input/ (e.g., input.docx)

License

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.

Setup & Run

  1. Clone or download this repository.

  2. Place your input DOCX file at resources/input/input.docx.

  3. 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.

  4. Output files are saved in resources/output/:

    • output.pdf, output.html — the edited document (recolored heading + highlighted text)

Example Usage

# 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:java

Project Structure

project-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

Topics Covered

  • 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 Editor class for document editing and conversion
  • License setup for GroupDocs Editor for Java

FAQ

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.

Documentation

🔗 GroupDocs Editor for Java Documentation

About

Save Edited DOCX as PDF or HTML using GroupDocs Editor for Java

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages