这是我的代码,想要用java给word添加平铺水印,代码不报错,但是水印没加上,只有doc那个红头文字,求帮助,急
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 multiTextWatermark {
public static void main(String[] args) {
//加载示例文档
Document doc = new Document();
doc.loadFromFile("C:\Users\Test1\Desktop\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.green);
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);
//获取section的页眉
header = section.getHeadersFooters().getHeader();
Paragraph paragraph1;
for (int i = 0; i < 4; i++) {
//添加段落到页眉
paragraph1 = header.addParagraph();
for (int j = 0; j < 3; j++) {
//复制艺术字并设置多行多列位置
shape = (ShapeObject) shape.deepClone();
shape.setVerticalPosition(50 + 150 * i);
shape.setHorizontalPosition(20 + 160 * j);
paragraph1.getChildObjects().add(shape);
}
}
}
//保存文档
doc.saveToFile("output/multi-lineTextwatermark.docx", FileFormat.Docx_2013);
}
}