A watermark in a Word document is a semitransparent text or image background that is used to highlight something important about the document, such as using text watermark to remind the reader that the document is confidential or just a draft and declaring copyright through a picture of your company. Sometimes watermarks can affect the readability of documents, and if we want to remove them, Spire.Doc for Java will be of great help. This article shows the detailed steps of removing watermarks from Word documents with the help of Spire.Doc for Java.
Install Spire.Doc for Java
First, you're required to add the Spire.Doc.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.doc</artifactId> <version>12.11.0</version> </dependency> </dependencies>
Remove the Watermark from a Word Document
The detailed steps of removing a watermark are as follows:
- Create an object of Document.
- Load a Word document from disk using Document.loadFromFile() method.
- Set the watermark to null to remove the watermark using Document.setWatermark() method.
- Save the Word document using Document.saveToFile() method.
- Java
import com.spire.doc.*; public class removeWatermark { public static void main(String[] args) { //Create an object of Document Document document = new Document(); //Load a Word document from disk document.loadFromFile("D:/testp/test.docx"); //Set the watermark value to null to remove the watermark document.setWatermark(null); //Save the Word document String output = "D:/javaOutput/removeWatermark.docx"; document.saveToFile(output, FileFormat.Docx_2013); } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.