Add multi-letter watermark to Java Word

Previously I showed you how to add a watermark to Word, but this time I'll show you how to add a watermark of multiple characters to Word. You can easily do this using a library called Free Spire.Doc for Java.

Preparation

1. From the official website of E-iceblue Free Spire.doc for Download the free version of Java .

f:id:lendoris:20210114145341p:plain

2. Start the IDE, create a new project, and then add the appropriate Spire.doc.jar to the reference that was in the installed file.

f:id:lendoris:20210114145406p:plain

code

```java import com.spire.doc.Document; import com.spire.doc.FileFormat; import com.spire.doc.HeaderFooter; import com.spire.doc.Section; import com.spire.doc.documents.Paragraph; import com.spire.doc.documents.ShapeLineStyle; import com.spire.doc.documents.ShapeType; import com.spire.doc.fields.ShapeObject; import java.awt.*;

public class Watermark { public static void main(String[] args) { //Load the document. Document doc = new Document(); doc.loadFromFile("C:\Users\Test1\Desktop\Sample.docx"); //Add WordArt shape and set the size ShapeObject shape = new ShapeObject(doc, ShapeType.Text_Plain_Text); shape.setWidth(50); shape.setHeight(15); //Place the position and format of the text. shape.setVerticalPosition(20); shape.setHorizontalPosition(20); shape.setRotation(315); shape.getWordArt().setText("Copying prohibited"); shape.setFillColor(Color.red); shape.setLineStyle(ShapeLineStyle.Single); shape.setStrokeColor(new Color(192, 192, 192, 255)); shape.setStrokeWeight(1);

    Section section;
    HeaderFooter header;
    for (int n = 0; n < doc.getSections().getCount(); n++) {
        section = doc.getSections().get(n);
        //Get the header of section
        header = section.getHeadersFooters().getHeader();
        Paragraph paragraph1;
        for (int i = 0; i < 4; i++) {
            //Add the header to the paragraph
            paragraph1 = header.addParagraph();
            for (int j = 0; j < 3; j++) {
                //Copy the text.
                shape = (ShapeObject) shape.deepClone();
                shape.setVerticalPosition(40 + 120 * i);
                shape.setHorizontalPosition(20 + 130 * j);
                paragraph1.getChildObjects().add(shape);
            }
        }
    }
    //you save.
    doc.saveToFile("output/AddMultipleTextWatermark.docx", FileFormat.Docx_2013);
}

}

 <h4> <strong> Execution result </strong> </h4>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20210114/20210114145451.png " alt="f:id:lendoris:20210114145451p:plain" title="" class="hatena-fotolife" itemprop="image" /></p>
<p> </p>


Recommended Posts

Add multi-letter watermark to Java Word
Add watermark to Java to PDF document
[Java] Add WordArt to Word document
Add / remove watermark to Java PowerPoint
Add footnotes to Word documents in Java
Java adds hyperlinks to Word documents
Java (add2)
Java (add)
[Java] How to add data to List (add, addAll)
Add Document to Azure Search Service (Java)
How to print a Java Word document
Add SameSite attribute to cookie in Java
[Java] Introduction to Java
Introduction to java
[Java] Add quotes only to specific CSV columns
[Java] Article to add validation with Spring Boot 2.3.1.
Desktop: OpenCV Add WaterMark
Add files to jar files
Changes from Java 8 to Java 11
Sum from Java_1 to 100
[Java] Connect to MySQL
PKIX path building failed: Add SSL certificate to java
Use Maven to add your favorite Java library to your environment.
Kotlin's improvements to Java
Java applications convert Word (DOC / DOCX) documents to PDF
[Java] Initialize, add, get
Merge Java Word documents
From Java to Ruby !!
[Java] [XML signature] Add prefix and ID to Signature tag
Introduction to java command
java: Add date [Note]
Java reserved word summary
[Java] How to use Map
How to lower java version
Migration from Cobol to JAVA
[Java] How to use Map
Convert Java Powerpoint to XPS
Java adds table to PDF
How to uninstall Java 8 (Mac)
Java to play with Function
Java --How to make JTable
How to add ActionText function
How to use java Optional
New features from Java7 to Java8
How to minimize Java images
How to write java comments
How to use java class
Output javadoc to word file
[Java] How to use Optional ②
Connect from Java to PostgreSQL
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] Introduction to lambda expressions
4 Add println to the interpreter
[Java] How to use string.format
Shell to kill Java process
How to use Java Map
How to set Java constants
Connect to DB with Java
Connect to MySQL 8 with Java
[java] Reasons to use static