标签:nes depend src getch r文件 sample jar包 setfill 页眉
在Word设置水印时,通常设置文本字样的水印只能在页面中设置一个水印字样,若需要在Word中设置平铺水印效果,可以参考以下方法。<repositories>
<repository>
<id>com.e-iceblue</id>
<url>http://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId> e-iceblue </groupId>
<artifactId>spire.doc.free</artifactId>
<version>2.7.3</version>
</dependency>
</dependencies>
Jar导入结果:
Java 代码
import com.spire.doc.*;
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 TextWatermark {
public static void main(String[] args) {
//加载示例文档
Document doc = new Document();
doc.loadFromFile("sample.docx");
//添加艺术字并设置大小
ShapeObject shape = new ShapeObject(doc, ShapeType.Text_Plain_Text);
shape.setWidth(60);
shape.setHeight(20);
//设置艺术字文本内容、位置及样式(即文本水印字样)
shape.setVerticalPosition(30);
shape.setHorizontalPosition(20);
shape.setRotation(315);
shape.getWordArt().setText("内部使用");
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);
//获取页眉
header = section.getHeadersFooters().getHeader();
Paragraph paragraph1;
for (int i = 0; i < 4; i++) {
//添加4个段落到页眉
paragraph1 = header.addParagraph();
for (int j = 0; j < 3; j++) {
//复制艺术字并设置多行多列位置
shape = (ShapeObject) shape.deepClone();
shape.setVerticalPosition(50 + 200 * i);
shape.setHorizontalPosition(20 + 160 * j);
paragraph1.getChildObjects().add(shape);
}
}
}
//保存文档
doc.saveToFile("result.docx", FileFormat.Docx_2013);
doc.dispose();
}
}
水印添加效果:
(完)
标签:nes depend src getch r文件 sample jar包 setfill 页眉
原文地址:https://blog.51cto.com/eiceblue/2528110