「wordjava水印」word2007水印
本篇文章给大家谈谈wordjava水印,以及word2007水印对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
java怎么实现在线打开word时给word加水印?
package com.ymo.word;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class TestJacobWord {
private ActiveXComponent wrdCom = null;
private Dispatch doc = null;
private Dispatch activeDoc = null;
private Dispatch docSelect = null;
private Dispatch docs = null;
private static TestJacobWord instance = null;
private String docName = "";
public static TestJacobWord getInstance() {
if (instance == null) {
instance = new TestJacobWord();
}
return instance;
}
private boolean initWord() {
boolean flag = false;
ComThread.InitSTA();
wrdCom = new ActiveXComponent("word.Application");
try {
docs = wrdCom.getProperty("Documents").toDispatch();
wrdCom.setProperty("Visible", new Variant(false));
flag = true;
} catch (Exception e) {
flag = false;
e.printStackTrace();
}
return flag;
}
private void createNewDocument() {
doc = Dispatch.call(docs, "Add").toDispatch();
docSelect = Dispatch.get(wrdCom, "Selection").toDispatch();
}
private void getActiveDoc() {
activeDoc = wrdCom.getProperty("ActiveWindow").toDispatch();
System.out.println(activeDoc.getProgramId());
}
private void openDocument(String docPath) {
if (this.doc != null) {
closeDocument();
}
this.doc = Dispatch.call(docs, "Open", docPath, new Variant(false),
new Variant(false)).toDispatch();
docSelect = Dispatch.get(wrdCom, "Selection").toDispatch();
}
private void closeDocument() {
if (doc != null) {
Dispatch.call(doc, "Save");
Dispatch.call(doc, "Close", new Variant(true));
doc = null;
}
}
private void setImgWaterMark(String waterMarkPath) {
Dispatch activePan = Dispatch.get(activeDoc, "ActivePane").toDispatch();
Dispatch view = Dispatch.get(activePan, "View").toDispatch();
Dispatch.put(view, "SeekView", new Variant(9));
Dispatch headfooter = Dispatch.get(docSelect, "HeaderFooter")
.toDispatch();
// 取得图形对象
Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch();
Dispatch pic = Dispatch.call(shapes, "AddPicture", waterMarkPath)
.toDispatch();
Dispatch.call(pic, "Select");
Dispatch.put(pic, "Left", new Variant(10));
Dispatch.put(pic, "Top", new Variant(200));
Dispatch.put(pic, "Width", new Variant(150));
Dispatch.put(pic, "Height", new Variant(80));
Dispatch.put(view, "SeekView", new Variant(0));
}
public void setTextWaterMark(String waterMarkStr) {
Dispatch activePan = Dispatch.get(activeDoc, "ActivePane").toDispatch();
Dispatch view = Dispatch.get(activePan, "View").toDispatch();
Dispatch.put(view, "SeekView", new Variant(9));
Dispatch headfooter = Dispatch.get(docSelect, "HeaderFooter")
.toDispatch();
Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch();
Dispatch selection = Dispatch.call(shapes, "AddTextEffect",
new Variant(9), waterMarkStr, "宋体", new Variant(1),
new Variant(false), new Variant(false), new Variant(0),
new Variant(0)).toDispatch();
Dispatch.call(selection, "Select");
Dispatch shapeRange = Dispatch.get(docSelect, "ShapeRange")
.toDispatch();
Dispatch.put(shapeRange, "Name", "PowerPlusWaterMarkObject
1");
Dispatch textEffect = Dispatch.get(shapeRange, "TextEffect")
.toDispatch();
Dispatch.put(textEffect, "NormalizedHeight", new Boolean(false));
Dispatch line = Dispatch.get(shapeRange, "Line").toDispatch();
Dispatch.put(line, "Visible", new Boolean(false));
Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch();
Dispatch.put(fill, "Visible", new Boolean(true));
// 设置水印透明度
Dispatch.put(fill, "Transparency", new Variant(0.5));
Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch();
Dispatch.put(foreColor, "RGB", new Variant(16711620));
Dispatch.call(fill, "Solid");
// 设置水印旋转
Dispatch.put(shapeRange, "Rotation", new Variant(315));
Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true));
Dispatch.put(shapeRange, "Height", new Variant(117.0709));
Dispatch.put(shapeRange, "Width", new Variant(468.2835));
Dispatch.put(shapeRange, "Left", new Variant(-999995));
Dispatch.put(shapeRange, "Top", new Variant(-999995));
Dispatch wrapFormat = Dispatch.get(shapeRange, "WrapFormat")
.toDispatch();
// 是否允许交叠
Dispatch.put(wrapFormat, "AllowOverlap", new Variant(true));
Dispatch.put(wrapFormat, "Side", new Variant(3));
Dispatch.put(wrapFormat, "Type", new Variant(3));
Dispatch.put(shapeRange, "RelativeHorizontalPositi
on", new Variant(0));
Dispatch.put(shapeRange, "RelativeVerticalPosition
", new Variant(0));
Dispatch.put(view, "SeekView", new Variant(0));
}
private void closeWord() {
// 关闭word文件
wrdCom.invoke("Quit", new Variant[] {});
// 释放com线程
ComThread.Release();
}
public String getDocName() {
return docName;
}
public void setDocName(String docName) {
this.docName = docName;
}
private boolean addWaterMark(String wordPath, String waterMarkPath) {
boolean flag = false;
try {
if (initWord()) {
openDocument(wordPath);
getActiveDoc();
setImgWaterMark(waterMarkPath);
closeDocument();
closeWord();
flag = true;
} else {
flag = false;
}
} catch (Exception e) {
flag = false;
e.printStackTrace();
closeDocument();
closeWord();
}
return flag;
}
public static void main(String[] args) {
TestJacobWord jacob = TestJacobWord.getInstance();
// jacob.addWaterMark("F://test//test.doc", "F://test//ymo.jpg");
try {
if (jacob.initWord()) {
jacob.openDocument("F://test/test.doc");
jacob.getActiveDoc();
jacob.setTextWaterMark("重庆宇能科技有限公司");
jacob.closeDocument();
jacob.closeWord();
}
} catch (Exception e) {
e.printStackTrace();
jacob.closeDocument();
jacob.closeWord();
}
}
}
怎么给word文档添加水印?
1/10
首先打开word文档
2/10
点击word顶部的设计
3/10
点击设计之后,在右边点击水印
4/10
任意双击一种水印,即可添加水印成功
5/10
用这种方法添加的水印也很容易被人删除,设计-水印-删除水印即可被删除,
6/10
上面介绍的方法中,水印很容易被人删除,如此我们设置的水印效果并不是很大,下面在介绍另一种不易被察觉的水印添加方法,双击页眉位置
7/10
出现页面之后,再点击插入-文本框-简单文本框,再出现文本框之后,输入我们想要的内容,并且把文字放大一点,右边会有一个小框,点击
8/10
把鼠标移动到页眉边框,会出现一个小十字光标,点击后将水印的整个框往下拖一点,并且鼠标点击旋转标识不放可将页眉旋转至倾斜
9/10
然后再按如下设置形状轮廓和形状填充
10/10
最后双击非页眉位置退出页眉状态,即可添加自制水印成功,这种方式添加水印可能很多人就不知道怎么删除了
怎么用java代码给word加水印
目前能够支持Java语言去操作word文档的框架很多,什么Jacob,jcom,poi,Java2word等等,但是那一种是支持给word加水印的框架呢?最好是开源的框架。
word水印怎么设置
Word中设置水印的方法如下:
工具/原料:Dell游匣G15、win10、Word2016
1、首先打开Word,新建一个空白演示文稿。
2、然后选择工具条上的设计选项卡。
3、切换到设计选项卡后,点击水印选项。
4、弹出的面板中选择需要的水印效果,如果没有合适的,可以点击下方的自定义水印。
5、打开自定义水印窗口后,设置需要的水印,可以设置文字水印或图片水印,设置好相关参数后,点击确定即可。
wordjava水印的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于word2007水印、wordjava水印的信息别忘了在本站进行查找喔。