PPTX
DOCX
XLSX
PDF
ODP
DOCX
Add Text Watermark to DOCX via Java
Build your own Java apps to watermark Microsoft Word DOCX files using server-side APIs.
How to Watermark DOCX File Using Java
In order to watermark Micrososft Word DOCX file, we’ll use
API which is a feature-rich, powerful and easy to use warermarking 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 Add Watermark to DOCX via Java
- Load DOCX file with an instance of Document
- Create an instance of TextWatermarkOptions and set its properties
- Call Watermark.setText method and pass watermark text & object of TextWatermarkOptions
- Save the document with text watermark
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.
Add Watermark to DOCX - Java
//adding text watermark
Document docx = new Document(dataDir + "Document.docx");
TextWatermarkOptions options = new TextWatermarkOptions();
options.setFontFamily("Arial");
options.setFontSize(36);
options.setColor(Color.BLACK);
options.setLayout(WatermarkLayout.HORIZONTAL);
options.isSemitrasparent(false);
docx.getWatermark().setText("Test", options);
docx.save(dataDir + "AddTextWatermark_out.docx");
// similarly adding image watermark is with just few lines of code
Java Words API can be used to load, view and convert Microsoft Word and OpenDocument Formats like DOC, DOCX, ODT to PDF, XPS, HTML and various other formats. You can also create new documents from scratch and save them in the supported formats. It is a standalone API that is suitable for server side and backend systems where high performance is required. It does not depend on any software like Microsoft or OpenOffice.