Java adds and removes watermarks in word documents

Word watermarks can be divided into two types: text watermarks and picture watermarks. Text watermarks indicate the current state of the document, drafts, confidentiality, certified, etc. Photo watermarks can be used to specify the logo of a company. This article will show you how to use Java and Free Spire.Doc for Java How to add document watermarks and photo watermarks to Word documents and remove watermarks from Word documents.

Add Text Watermark: TextWatermark class Manipulate text watermarks. When creating a text watermark, you can customize the text watermark attributes such as font, size, font color, and watermark layout style.


import com.spire.doc.*;
import com.spire.doc.documents.WatermarkLayout;
import java.awt.*;

public class WordTextWatermark {
    public static void main(String[] args) {

        Document document = new Document();
        document.loadFromFile("Sample.docx");

        insertTextWatermark(document.getSections().get(0));

        document.saveToFile("out/result.docx",FileFormat.Docx );
    }
    private static void insertTextWatermark(Section section) {
        TextWatermark txtWatermark = new TextWatermark();
        txtWatermark.setText("Internal use");
        txtWatermark.setFontSize(40);
        txtWatermark.setColor(Color.red);
        txtWatermark.setLayout(WatermarkLayout.Diagonal);
        section.getDocument().setWatermark(txtWatermark);
    }

}

Output:

Text watermark.png

Add Image Watermark: PictureWatermark class For manipulating image watermarks. The watermark photo can be from the local area. It also comes from streams created in other projects.


import com.spire.doc.*;


public class WordImageWatermark {
    public static void main(String[] args)  throws Exception{

        Document document = new Document();
        document.loadFromFile("Sample.docx");

         PictureWatermark picture = new PictureWatermark();
         picture.setPicture("logo.png ");
         picture.setScaling(5);
         picture.isWashout(false);
         document.setWatermark(picture);

         document.saveToFile("out/result2.docx",FileFormat.Docx );
    }
}

Output: Image watermark.png

You can easily remove watermarks in Word documents using the method Remove Watermark, doc.setWatermark (null).

import com.spire.doc.*;
 
public class RemoveWatermark {
 
    public static void main(String[] args){
 
        Document doc = new Document();
        doc.loadFromFile("ImageWatermark.docx");
 
        doc.setWatermark(null);
 
        doc.saveToFile("RemoveWatermark.docx", FileFormat.Docx);
    }
}

Recommended Posts

Java adds and removes watermarks in word documents
Java joins and splitting table cells in Word documents
Add footnotes to Word documents in Java
Merge Java Word documents
Change paragraph text color in Java Word documents
Encoding and Decoding example in Java
StringBuffer and StringBuilder Class in Java
Understanding equals and hashCode in Java
Java encryption, decryption of Word documents
Java draws shapes in PDF documents
Java adds and reads Excel formulas
Hello world in Java and Gradle
Difference between final and Immutable in Java
[Java] for Each and sorted in Lambda
Java creates a table in a Word document
Arrylist and linked list difference in java
Program PDF headers and footers in Java
Learn Flyweight patterns and ConcurrentHashMap in Java
Java Direction in C ++ Design and Evolution
Java to C and C to Java in Android Studio
Reading and writing gzip files in Java
Difference between int and Integer in Java
Discrimination of Enums in Java 7 and above
[Java] [POI] Create a table in Word and start a new line in one cell
Regarding the transient modifier and serialization in Java
Detect similar videos in Java and OpenCV rev.2
Parallel and parallel processing in various languages (Java edition)
Difference between next () and nextLine () in Java Scanner
Differences in writing Java, C # and Javascript classes
Capture and save from selenium installation in Java
Detect similar videos in Java and OpenCV rev.3
Add, read, and delete Excel comments in Java
Check static and public behavior in Java methods
[Java] Understand in 10 minutes! Associative array and HashMap
Basics of threads and Callable in Java [Beginner]
Distinguish between positive and negative numbers in Java
Java adds page numbers to existing PDF documents
Detect similar videos in Java and OpenCV rev.1
Represents "next day" and "previous day" in Java / Android
Questions in java exception handling throw and try-catch
Upload and download notes in java on S3
Encrypt / decrypt with AES256 in PHP and Java
Generate OffsetDateTime from Clock and LocalDateTime in Java
Partization in Java
Rock-paper-scissors in Java
Java and JavaScript
XXE and Java
Pi in Java
FizzBuzz in Java
[Android / Java] Screen transition and return processing in fragments
Convert JSON and YAML in Java (using Jackson and SnakeYAML)
I tried Mastodon's Toot and Streaming API in Java
Write ABNF in Java and pass the email address
Organize builds in C ++ / Java and Win / Linux combinations
Vectorize and image MNIST handwritten digit image data in Java
Write a class in Kotlin and call it in Java
[Java] Difference between static final and final in member variables
Java applications convert Word (DOC / DOCX) documents to PDF
This and that for editing ini in Java. : inieditor-java
How to convert A to a and a to A using AND and OR in Java
Reverse Enum constants from strings and values in Java