word文档加完多行水印后电脑打开没有问题,
但是用微信或者qq传到手机里打开看就会有问题,
不同手机问题还不一样有显示没水印的,有显示文件已损坏的,
但是传回电脑,在电脑里看还是好的,
用U盘传到手机里也是好的
代码几乎和示例一摸一样
public void addVisibleDocxWaterMark(InputStream from, OutputStream to, String waterNode) throws Exception {
String shiyin = waterNode;
//加载示例文档
com.spire.doc.Document doc = new com.spire.doc.Document();
// doc.loadFromFile(from);
doc.loadFromStream(from, FileFormat.Docx_2013);
//添加艺术字并设置大小
ShapeObject shape = new ShapeObject(doc, ShapeType.Text_Plain_Text);
shape.setWidth(80);
shape.setHeight(30);
//设置艺术字文本内容、位置及样式
shape.setVerticalPosition(30);
shape.setHorizontalPosition(20);
shape.setRotation(315);
shape.getWordArt().setFontFamily("宋体");
shape.getWordArt().setText(shiyin);
// shape.setFillColor(Color.RED);
shape.setLineStyle(ShapeLineStyle.Single);
shape.setStrokeColor(new Color(188, 188, 188, 1));
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 paragraph;
if (header.getParagraphs().getCount() > 0) {
//如果页眉有段落,取它第一个段落
paragraph = header.getParagraphs().get(0);
} else {
//否则新增加一个段落到页眉
paragraph = header.addParagraph();
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
//复制艺术字并设置多行多列位置
shape = (ShapeObject) shape.deepClone();
shape.setVerticalPosition(50 + 150 * i);
shape.setHorizontalPosition(20 + 160 * j);
paragraph.getChildObjects().add(shape);
}
}
}
//保存文档
doc.saveToFile(to, FileFormat.Docx_2013);
}