Redact DOCX Formats in Java
Native and high performance Microsoft Word DOCX document sensitive redaction information using Java APIs, without the use of any software like Microsoft or Adobe PDF.
How to Redact DOCX File Using Java
In order to redact Microsoft Word DOCX file, we’ll use
API which is a feature-rich, powerful and easy to use redaction API for Java platform. You can download its latest version directly from
and install it within your Maven-based project by adding the following configurations to the pom.xml.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>version of aspose-words API</version>
<classifier>jdk17</classifier>
</dependency>
Steps to Redact DOCX Files in Java
A basic document search and replace text in contents, comments or metadata can be done with just few lines of code. Redact sensitive information through search and replace text in contents, comments or metadata in Word documents.
- Instantiate Document class..
- Create FindReplaceOptions object.
- Set Pattern
- Use Replace method with relevant options.
- Save document.
System Requirements
Before integrating the code, make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Get latest version of Aspose.Words for Java directly from Maven .
Redact DOCX Files - Java
Document docx = new Document();
DocumentBuilder builder = new DocumentBuilder(docx);
builder.writeln("sad mad bad");
if(docx.getText().trim() == "sad mad bad"){
System.out.println("Strings are equal!");
}
// Replaces all occurrences of the words "sad" or "mad" to "bad".
FindReplaceOptions options = new FindReplaceOptions();
docx.getRange().replace(Pattern.compile("[s|m]ad"), "bad", options);
// Save the DOCX document.
docx.save(dataDir + "output.docx");
Online DOCX Redaction Live Demos
DOCX What is DOCX File Format
DOCX is a well-known format for Microsoft Word documents. Introduced from 2007 with the release of Microsoft Office 2007, the structure of this new Document format was changed from plain binary to a combination of XML and binary files. Docx files can be opened with Word 2007 and lateral versions but not with the earlier versions of MS Word which support DOC file extensions.
Read MoreOther Supported Redaction Documents
Using Java, one can easily redact different formats including.