# 3 Document Redaction Methods for Word DOCX - Complete Comparison Guide Compare 3 methods to redact Word DOCX using GroupDocs.Redaction for Node.js via Java. Detailed comparison, code examples, and best practices. # Redact documents with Node.js API {{< alert style="info" >}} 💡 Full working example available on GitHub: [redact-word-documents-nodejs-api](https://github.com/groupdocs-redaction/redact-word-documents-nodejs-api) {{< /alert >}} ## Introduction Document redaction is a GroupDocs.Redaction capability for Node.js via Java that replaces sensitive DOCX text and clears metadata before a file is shared. Teams that publish Word packets from Node.js need pattern-based removal, exact-phrase substitution, and metadata wipe - native OOXML edits rarely cover all three without custom parsers for runs, headers, and properties. This guide compares 3 methods to redact Word DOCX using GroupDocs.Redaction for Node.js via Java, focusing on match behavior and when each rule should lead an export pipeline. I needed this comparison when a Node.js export job had to scrub both a regex-matched phrase and the Author property from the same DOCX before it reached an external counsel drop folder. ## What This Guide Covers You will see how `RegexRedaction`, `ExactPhraseRedaction`, and `EraseMetadataRedaction` differ, when to combine them, and how stream save keeps DOCX editable. The matrix maps common scenarios to a primary method. **Prerequisites:** - Node.js LTS with npm, plus a JDK and node-gyp/MSVC toolchain for the Java bridge - `@groupdocs/groupdocs.redaction` 26.11.0 and a sample DOCX such as `documents/document.docx` {{< alert style="info" >}} **Complete Source Code:** All examples are available in our [GitHub repository](https://github.com/groupdocs-redaction/redact-word-documents-nodejs-api). Clone, run, and customize for your needs. {{< /alert >}} ## How do I choose between regex, exact phrase, and metadata erase? Start from the data you must remove. If identifiers follow a pattern with optional whitespace or digits, use `RegexRedaction` with `ReplacementOptions`. If counsel asks for a fixed legal phrase to become a token, use `ExactPhraseRedaction`. If body text is already clean but Author or Company fields remain, apply `EraseMetadataRedaction` with `MetadataFilters.All`. Most export pipelines run a text method first, then metadata erase so properties cannot reintroduce ownership data. ## Quick Decision Matrix | Scenario | Recommended Method | Why | |----------|------------------|-----| | Patterned PII or spaced phrases | RegexRedaction | Regex matches variants exact text cannot | | Fixed policy or legal phrase | ExactPhraseRedaction | Literal match avoids regex false positives | | Author/company must be blank | EraseMetadataRedaction | Clears metadata filters in one apply call | | External DOCX must stay editable | Any + stream save | Rasterization disabled keeps Word format | | Combine text + properties wipe | Text method then erase | Metadata wipe after body redaction | ## Method Comparison Overview | Method | Complexity | Performance | Flexibility | Best For | |--------|-----------|-------------|-------------|----------| | **RegexRedaction** | Medium | High for targeted patterns | High | Structured identifiers and flexible matches | | **ExactPhraseRedaction** | Low | High for fixed strings | Medium | Known phrases with stable wording | | **EraseMetadataRedaction** | Low | High (metadata only) | Medium | Clearing author, company, and related fields | ## Detailed Method Analysis ### Method 1: RegexRedaction **Overview:** `RegexRedaction` replaces document text that matches a regular expression. Pair it with `ReplacementOptions` so every match becomes a caller-defined string such as ` [redacted]`. #### How It Works Open the DOCX with `Redactor`, construct `RegexRedaction` from the pattern and replacement options, then call `apply`. When the status is not `Failed`, save through `FileOutputStream` with `RasterizationOptions` disabled so the output remains editable Word. Close the redactor in a `finally` block to release native resources. #### When to Use - ✅ Patterned codes or phrases with optional whitespace - ✅ One rule covering multiple textual variants - ✅ Config-driven pipelines that store regex strings outside code - ❌ Not recommended for: fixed legal phrases better served by exact match #### Implementation ```javascript const redactor = new redaction.Redactor(sourcePath); const result = redactor.apply( new redaction.RegexRedaction( pattern, new redaction.ReplacementOptions(replacement) ) ); ``` ```javascript if (result.getStatus() !== redaction.RedactionStatus.Failed) { const rasterizationOptions = new redaction.RasterizationOptions(); rasterizationOptions.setEnabled(false); const output = new FileOutputStream(path.resolve(outputPath)); try { redactor.save(output, rasterizationOptions); } finally { output.close(); } } redactor.close(); ``` #### Pros and Cons **Advantages:** - One pattern covers many textual variants - Fits config-driven redaction lists - Shares the same `Redactor` and stream-save path as other methods **Limitations:** - Loose regex can over-match safe text - Higher authoring cost than exact phrase for fixed strings ### Method 2: ExactPhraseRedaction **Overview:** `ExactPhraseRedaction` replaces every occurrence of a literal phrase with a token. Prefer it when wording never changes and regex would add risk without extra coverage. #### How It Works Create `ExactPhraseRedaction` with the phrase and a string `ReplacementOptions` value, apply it on a `Redactor`, then stream-save when status is successful. Matching targets the full phrase rather than a compiled pattern, which keeps the call site short and easy to audit against a legal phrase list. #### When to Use - ✅ Fixed phrases such as slogans or clause titles - ✅ Compliance lists of exact strings from legal teams - ✅ Cases where regex complexity is unnecessary - ❌ Not recommended for: identifiers that vary by digit or spacing #### Implementation ```javascript const redactor = new redaction.Redactor(sourcePath); const result = redactor.apply( new redaction.ExactPhraseRedaction( phrase, new redaction.ReplacementOptions(replacement) ) ); if (result.getStatus() !== redaction.RedactionStatus.Failed) { saveAsOriginalFormat(redactor, outputPath); } redactor.close(); ``` #### Pros and Cons **Advantages:** - Simple parameters: phrase plus replacement token - Lower chance of accidental over-redaction than broad regex - Easy to audit against a spreadsheet of banned phrases **Limitations:** - Does not catch near-matches or whitespace variants - Requires an updated list when wording changes ### Method 3: EraseMetadataRedaction **Overview:** `EraseMetadataRedaction` clears document metadata so author, company, and related fields do not leave with the file. Use `MetadataFilters.All` when every supported property category must be blanked. #### How It Works Load the DOCX, apply `EraseMetadataRedaction` with `MetadataFilters.All`, check status, then save with rasterization disabled. This targets property bags rather than body runs, so it complements text redaction instead of replacing it in a Node.js export workflow. #### When to Use - ✅ Pre-share exports that must hide Author and Company - ✅ After text redaction when properties might still leak identity - ✅ Automated packages where reviewers skip File > Info checks - ❌ Not recommended for: body-text removal without a text method #### Implementation ```javascript const redactor = new redaction.Redactor(sourcePath); const result = redactor.apply( new redaction.EraseMetadataRedaction( redaction.MetadataFilters.All ) ); if (result.getStatus() !== redaction.RedactionStatus.Failed) { saveAsOriginalFormat(redactor, outputPath); } return result.getStatus(); ``` #### Pros and Cons **Advantages:** - One call clears the full filter set with `MetadataFilters.All` - Prevents ownership leaks that body search never sees - Same save path as text redaction keeps tooling consistent **Limitations:** - Does not remove sensitive body text by itself - Overwrites metadata some internal archives may want to keep ## Real-World Use Cases ### Use Case 1: Patterned phrase scrub before counsel review **Challenge:** A Node.js export must remove a spaced product phrase with irregular whitespace. **Solution:** `RegexRedaction` with a pattern such as `\\s+essential tool`. **Result:** Counsel receives an editable DOCX without rasterizing the file. ### Use Case 2: Fixed disclaimer token for partner packs **Challenge:** Partner packs must replace a fixed marketing phrase with `[REDACTED]`. **Solution:** `ExactPhraseRedaction` with string `ReplacementOptions`. **Result:** Reviewers confirm the token in Word without regex near-matches. ### Use Case 3: Strip ownership before public upload **Challenge:** Author and Company still appear under File properties after text cleanup. **Solution:** `EraseMetadataRedaction` with `MetadataFilters.All`. **Result:** The uploaded DOCX no longer exposes internal ownership fields. ## When to use this approach Choose GroupDocs.Redaction for Node.js via Java when your service already runs on Node.js but you need Java-parity redaction types without rewriting the app. Prefer this stack when DOCX must stay editable and metadata erase must sit next to text rules in the same package. ## Best Practices and Recommendations Keep patterns narrow, always `close()` the redactor, and gate save on a non-failed `RedactionStatus`. Disable rasterization for editable Word output, then follow text redaction with `EraseMetadataRedaction` when packages leave the trust boundary. Document JDK and node-gyp requirements for `@groupdocs/groupdocs.redaction` 26.11.0, and obtain a [temporary license](https://purchase.groupdocs.com/temporary-license) when evaluation limits interfere with review. ## Common Pitfalls and How to Avoid Them 1. **Saving after a Failed status** — Gate save on a non-failed status, as the sample methods do. 2. **Leaving rasterization enabled** — Call `RasterizationOptions.setEnabled(false)` before `redactor.save`. 3. **Skipping metadata erase** — Apply `EraseMetadataRedaction` with `MetadataFilters.All` before distribution. 4. **Missing JDK or MSVC tools** — Install a JDK and node-gyp prerequisites before `npm install`. ## FAQ **Q: Which method is fastest?** A: `EraseMetadataRedaction` is usually lightest because it targets properties rather than scanning body text. Exact phrase and regex are similar for short patterns; prefer correct matching over micro-optimizing apply. **Q: Can I combine multiple methods?** A: Yes. Apply a text redaction first, then erase metadata so properties do not reintroduce ownership data. Check `RedactionStatus` after each apply before continuing the export. **Q: What's the learning curve for each method?** A: `ExactPhraseRedaction` and `EraseMetadataRedaction` are the shortest call sites. `RegexRedaction` needs regex tests for over-matching. All three share the same `Redactor` and stream-save pattern. **Q: Are there any licensing considerations?** A: Without a license file the API runs in evaluation mode. Set the path to a valid `.lic` from the [temporary license](https://purchase.groupdocs.com/temporary-license) page. Keep real license files out of public repositories. **Q: How do I choose the right method for my project?** A: Map each sensitive item to pattern, exact phrase, or metadata. Use the decision matrix and the companion [blog article](https://blog.groupdocs.com/redaction/redact-documents-with-nodejs-api-nodejs/), then validate with the GitHub sample. ## Conclusion GroupDocs.Redaction for Node.js via Java gives three complementary ways to prepare DOCX files for safer sharing: regex replacement, exact-phrase tokens, and full metadata erase. Match the method to the data type, confirm statuses, then wire the same calls into your export pipeline. **Next Steps:** - Explore the [complete source code](https://github.com/groupdocs-redaction/redact-word-documents-nodejs-api) on GitHub - Review the [API documentation](https://reference.groupdocs.com/redaction/java/) for advanced features - Read the companion [blog tutorial](https://blog.groupdocs.com/redaction/redact-documents-with-nodejs-api-nodejs/) ## See Also - [In-depth blog article: redact documents with Node.js API](https://blog.groupdocs.com/redaction/redact-documents-with-nodejs-api-nodejs/) - [Text redactions for Node.js via Java](https://docs.groupdocs.com/redaction/nodejs-java/text-redactions/) - [Redact text on Windows (Node.js via Java)](https://docs.groupdocs.com/redaction/nodejs-java/redact-text-windows/) - [Product documentation](https://docs.groupdocs.com/redaction/nodejs-java/) - [API Reference](https://reference.groupdocs.com/redaction/java/) - [GitHub repository](https://github.com/groupdocs-redaction/redact-word-documents-nodejs-api)