精华内容
下载资源
问答
  • word加水印

    千次阅读 2016-12-08 10:11:44
    word加水印 相关的jar包:jacob-1.17-x64.rar 注意区分32位和64系统复制 jacob-1.17-M4-x64.dll 放在java jdk bin目录下、系统目录/WINDOWS/system32目录下 代码如下:public class TestWaterWord { public ...

    word加水印

    相关的jar包:jacob-1.17-x64.rar
    注意区分32位和64系统
    复制 jacob-1.17-M4-x64.dll 放在java jdk bin目录下、系统目录/WINDOWS/system32目录下

    代码如下:

    public class TestWaterWord {
        public TestWaterWord() {}
        private static TestWaterWord instance;
        private Dispatch aDoc = null;//用于存储一个文档:比如新增一个文档时返回,新增的文档
        private Dispatch activeWindow = null;//当前活动窗口
        private Dispatch docSelection = null;//存储当前被选中文档
        private Dispatch wordDocs = null;//存储所有的文档
        private String fileName;
        private ActiveXComponent wordApp;//Word对象
        public final static synchronized TestWaterWord getInstance() {
            if (instance == null){
                instance = new TestWaterWord();
            }
            return instance;
        }
    
        /*** 初始化Word对象*/
        public boolean initWordApp() {
            boolean retFlag = false;
            //初始化com线程【相当于打开冰箱门,准备放大箱】
            //使用结束后要调用 realease方法关闭线程【相当于关上冰箱门】
            ComThread.InitSTA();
            wordApp = new ActiveXComponent("Word.Application");// 初始化word应用程序,初始化表格是:Excel.Application
            try {
                wordApp.setProperty("Visible", new Variant(false));//配置启动word时是显示执行还是隐式执行
                wordDocs = wordApp.getProperty("Documents").toDispatch();// 获取word所有文档对象
                retFlag = true;
            } catch (Exception e) {
                retFlag = false;
                e.printStackTrace();
            }
            return retFlag;
        }
    
        /**打开一个已存在的文档*/
        public void openDocument(String docPath) {
            if (this.aDoc != null) {
                this.closeDocument();
            }
            aDoc = Dispatch.call(wordDocs,"Open",new Variant(docPath)).toDispatch();//docPath要打开的文档的详细地址
            docSelection = Dispatch.get(wordApp, "Selection").toDispatch();//获得该文档对象,并返回
        }
    
        /** 取得活动窗体对象*/
        public void getActiveWindow() {
            activeWindow = wordApp.getProperty("ActiveWindow").toDispatch();// 取得活动窗体对象
        }
    
        /***创建一个新的word文档*/
        public void createNewDocument() {
            aDoc = Dispatch.call(wordDocs, "Add").toDispatch();//创建一个新的word文档,并返回
            docSelection = Dispatch.get(wordApp, "Selection").toDispatch();//获得该文档对象,并返回
        }
    
        /*** 保存并关闭当前word文档*/
        public void closeDocument() {
            if (aDoc != null) {
                Dispatch.call(aDoc, "Save");//保存
                Dispatch.call(aDoc, "Close", new Variant(0));//关闭
                aDoc = null;
            }
        }
    
        /*** 关闭Word资源*/
        public void closeWordObj() {
            wordApp.invoke("Quit", new Variant[] {});// 关闭word文件
            ComThread.Release();// 释放com线程。根据jacob的帮助文档,com的线程回收不由java的垃圾回收器处理
        }
    
        /**
         * 插入图片
         * @param pages 总页数
         * @param imgPath 图片路径
         * @param left 距离左上角位置
         * @param top 距离上角位置
         */
        public void setImages(int pages,String imgPath,int left,int top){
            for(int i = 0; i < pages;i++){ 
                Dispatch selection = Dispatch.get(wordApp, "Selection").toDispatch(); 
                Dispatch inLineShapes = Dispatch.get(selection, "InLineShapes").toDispatch();
                Dispatch picture = Dispatch.call(inLineShapes, "AddPicture", imgPath).toDispatch();
                //选中图片 
                Dispatch.call(picture, "Select"); 
                //设置宽度高度 
                Dispatch.put(picture, "Width", new Variant(100));
                Dispatch.put(picture, "Height", new Variant(100)); 
                //设置图片相对左上角偏移位置
                selection = Dispatch.get(wordApp, "Selection").toDispatch();
                Dispatch shapeRange = Dispatch.get(selection, "ShapeRange").toDispatch();
                Dispatch.put(shapeRange, "Left", new Variant(left));
                Dispatch.put(shapeRange, "Top", new Variant(top));
    
                //翻到下一页 
                Dispatch browser = Dispatch.get(wordApp, "Browser").toDispatch();
                Dispatch.call(browser, "Next");
            }
        }
    
        /**
         * 设置页眉
         * @param waterMarkStr
         */
        public void setHeader(String headerStr) {
            Dispatch activePane = Dispatch.get(activeWindow, "ActivePane").toDispatch();// 活动窗格
            Dispatch view = Dispatch.get(activePane, "View").toDispatch();// 视窗对象
    
            Dispatch.put(view, "SeekView", new Variant(9));// 打开页眉,值为9,页脚值为10
            Dispatch headerfooter = Dispatch.get(docSelection, "HeaderFooter").toDispatch();// 获取页眉和页脚
    
            Dispatch range = Dispatch.get(headerfooter, "Range").toDispatch();//页眉赋值
            Dispatch.put(range, "Text", new Variant(headerStr));
    
            Dispatch font = Dispatch.get(range, "Font").toDispatch();//设置字体
            Dispatch.put(font, "Name", new Variant("微软雅黑"));
            Dispatch.put(font, "Bold", new Variant(true));
            Dispatch.put(font, "Size", 20);
            Dispatch.put(font, "Color", Integer.valueOf("0000FF",16).toString());//颜色是16进制倒着写,然后转10进制
    
            Dispatch.put(view, "SeekView", new Variant(0)); //0表示恢复视图;
        }
    
    
        /** 文档设置图片水印,waterPic水印图片路径*/
        public void setWaterPic(String waterPic) {
            Dispatch activePane = Dispatch.get(activeWindow, "ActivePane").toDispatch();// 活动窗格
            Dispatch view = Dispatch.get(activePane, "View").toDispatch();// 视窗对象
    
            Dispatch.put(view, "SeekView", new Variant(9));// 打开页眉,值为9,页脚值为10
            Dispatch headerfooter = Dispatch.get(docSelection, "HeaderFooter").toDispatch();// 获取页眉和页脚
    
            Dispatch shapes = Dispatch.get(headerfooter, "Shapes").toDispatch();// 获取水印图形对象
    
            //调用shapes对象的AddPicture方法将图片插入当前文档
            Dispatch picture  = Dispatch.call(shapes,"AddPicture",waterPic).toDispatch();
    
            Dispatch.call(picture, "Select");//选择当前word文档的图片水印
    
            Dispatch.put(picture, "Left", new Variant(120));//设置图片水印参数
            Dispatch.put(picture, "Top", new Variant(240));
            Dispatch.put(picture, "LockAspectRatio", new Boolean(true));//调整大小时保持其长宽比例不变
            Dispatch.put(picture, "Width", new Variant(120));
            Dispatch.put(picture, "Height", new Variant(90));
    
            Dispatch.put(view, "SeekView", new Variant(0));//关闭页眉,0表示恢复视图;
        }
    
        /** 文档设置文字水印--实质是设置页眉,将文字转为艺术字图片*/
        public void setWaterMark(String waterMarkStr) {
            Dispatch activePane = Dispatch.get(activeWindow, "ActivePane").toDispatch();// 活动窗格
            Dispatch view = Dispatch.get(activePane, "View").toDispatch();// 视窗对象
    
            Dispatch.put(view, "SeekView", new Variant(9));// 打开页眉,值为9,页脚值为10
            Dispatch headerfooter = Dispatch.get(docSelection, "HeaderFooter").toDispatch();// 获取页眉和页脚
    
            Dispatch shapes = Dispatch.get(headerfooter, "Shapes").toDispatch();// 获取水印图形对象
    
            /**插入文字,并转为图片:
             * 操作对象、方法、艺术字格式[0白色、1黑左下右上,2黑中上两下、3黑中小两大、4黑竖排、5黑中下两上]
             * 水印内容、字体、字体大小、字体是否粗体、字体是否斜体
             * 左边距、上边距
             */
            Dispatch selection = Dispatch.call(shapes, "AddTextEffect",new Variant(0), 
                    waterMarkStr, "微软雅黑", new Variant(10),new Variant(true), new Variant(false), 
                    new Variant(150),new Variant(250)).toDispatch();
    
            //选中当前文档水印
            Dispatch.call(selection, "Select");
            Dispatch shapeRange = Dispatch.get(docSelection, "ShapeRange").toDispatch();
    
            /**
             * 设置水印透明度和颜色
             */
            Dispatch.put(shapeRange, "Name", "PowerPlusWaterMarkObject6");
                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.1));// 设置水印透明度
    
                    Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch();
                    Dispatch.put(foreColor, "RGB", new Variant(255));// 设置水印颜色
    
                Dispatch.call(fill, "Solid");
    
            /**
             * 设置水印旋转角度、水印大小
             */
            Dispatch.put(shapeRange, "Rotation", new Variant(0));//旋转角度
            Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true));//调整大小时保持其长宽比例不变
            Dispatch.put(shapeRange, "Height", new Variant(10));//高
            Dispatch.put(shapeRange, "Width", new Variant(40));//宽
            Dispatch.put(shapeRange, "Left", new Variant(160));
            Dispatch.put(shapeRange, "Top", new Variant(270));
    
            Dispatch.put(view, "SeekView", new Variant(0));//0表示恢复视图;
        }
    
        public String getFileName() {
            return fileName;
        }
        public void setFileName(String fileName) {
            this.fileName = fileName;
        }
    
        //测试功能
        public static void main(String[] argv) {
            TestWaterWord d = TestWaterWord.getInstance();
            try {
                if (d.initWordApp()) {
                    d.openDocument("C:/Users/solexit06/Desktop/testWater.docx");
                    d.getActiveWindow();
    
                    String imgPath="C:/Users/solexit06/Desktop/Border.png";
                    d.setWaterPic(imgPath);//页中图片
    
                    Date date=Calendar.getInstance().getTime();
                    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
                    String waterDate=sdf.format(date);
                    d.setWaterMark(waterDate);//日期
    
                    d.setHeader("****科技");//页眉
    
                    d.closeDocument();
                } else{
                    System.out.println("初始化Word读写对象失败!");
                }
            } catch (Exception e) {
                System.out.println(e);
            }finally{
                d.closeWordObj();
            }
        }
        }
    
    展开全文
  • Word 加水印

    2019-12-15 22:27:50
    1.打开word->设计->水印->自定义水印 2.文字栏 输入想要标识的水印 3.附上文档内容-数学竞赛题 已知整数x,y,满足x+y+2xy=83,求解x+y的值? 解: x+y+2xy=83 2x+2y+4xy=166 2x+2y+4xy+1= (2x+1) (2y...

    1.打开word->设计->水印->自定义水印

    2.文字栏 输入想要标识的水印

    3.附上文档内容-数学竞赛题

    已知整数x,y,满足x+y+2xy=83,求解x+y的值?
    解:
    x+y+2xy=83
    2x+2y+4xy=166
    2x+2y+4xy+1= (2x+1) (2y+1) = 167
    且由于x,y均为整数,且167为质数。
    故(2x+1,2y+1)存在 (1,167) (167,1) (-1,-167) (-167,-1) 四种情况
    故2x+2y+2的值存在168,-168两种情况
    故x+y的值为 83或-85

     

    展开全文
  • 万千封印有个免费的第三方Free Spire.Doc for Java,操作Word文档的,支持水印功能,代码如下:1.文本水印importcom.spire.doc.*;importcom.spire.doc.documents.WatermarkLayout;importjava.awt.*;...

    d3acb2a76c084f20c1667c4863cee194.png

    万千封印

    有个免费的第三方Free Spire.Doc for Java,操作Word文档的,支持水印功能,代码如下:1.文本水印import com.spire.doc.*;

    import com.spire.doc.documents.WatermarkLayout;

    import java.awt.*;

    public class WordTextWatermark {

        public static void main(String[] args) {

            Document document = new Document();

            document.loadFromFile("Sample.docx");

            insertTextWatermark(document.getSections().get(0));

            document.saveToFile("out/result.docx",FileFormat.Docx );

        }

        private static void insertTextWatermark(Section section) {

            TextWatermark txtWatermark = new TextWatermark();

            txtWatermark.setText("内部使用");

            txtWatermark.setFontSize(40);

            txtWatermark.setColor(Color.red);

            txtWatermark.setLayout(WatermarkLayout.Diagonal);

            section.getDocument().setWatermark(txtWatermark);

        }

    }2.图片水印import com.spire.doc.*;

    public class WordImageWatermark {

        public static void main(String[] args)  throws Exception{

            Document document = new Document();

            document.loadFromFile("Sample.docx");

             PictureWatermark picture = new PictureWatermark();

             picture.setPicture("logo.png");

             picture.setScaling(5);

             picture.isWashout(false);

             document.setWatermark(picture);

             document.saveToFile("out/result2.docx",FileFormat.Docx );

        }

    }请参考原文

    展开全文
  • Python给Word加水印

    千次阅读 2020-05-08 23:05:52
    # coding:utf8 ...def getWordAddWatermark(): wordApp = win32com.client.DispatchEx("Word.Application") # 打开word进程 wordApp.Visible = True wordApp.DisplayAlerts = False doc = wordApp
    # coding:utf8
    import win32com
    from win32com.client import Dispatch, constants
    def getWordAddWatermark():
        wordApp = win32com.client.DispatchEx("Word.Application")  # 打开word进程
        wordApp.Visible = True
        wordApp.DisplayAlerts = False
        doc = wordApp.Documents.Add()  # 新建一个空白文件
    
        actDoc = wordApp.ActiveDocument
        Sect = actDoc.Sections(1).Range.Select()
        wordApp.ActiveWindow.ActivePane.View.SeekView = 9
        # selectObj = wordApp.Selection
    
        wordApp.Selection.HeaderFooter.Shapes.AddTextEffect(0, "DOt1x © QQ980469001", "等线", 1, False, False, 0, 0).Select()
        # shpObj = vart.Select()
        wordApp.Selection.ShapeRange.Name = '0' 
    
        wordApp.Selection.ShapeRange.TextEffect.NormalizedHeight = False
        wordApp.Selection.ShapeRange.Line.Visible = False
        wordApp.Selection.ShapeRange.Fill.Visible = True
        wordApp.Selection.ShapeRange.Fill.Solid
        wordApp.Selection.ShapeRange.Fill.ForeColor = 0
        wordApp.Selection.ShapeRange.Fill.Transparency = 0.5
        # 设置颜色
        wordApp.Selection.ShapeRange.Fill.ForeColor.ObjectThemeColor = 14
        wordApp.Selection.ShapeRange.Fill.ForeColor.TintAndShade = 0
        wordApp.Selection.ShapeRange.Rotation = 315
        wordApp.Selection.ShapeRange.LockAspectRatio = True
        wordApp.Selection.ShapeRange.Height = 120
        wordApp.Selection.ShapeRange.Width = 460
        wordApp.Selection.ShapeRange.WrapFormat.AllowOverlap = True
        # wordApp.Selection.ShapeRange.WrapFormat.Side = wdWrapNone
        wordApp.Selection.ShapeRange.WrapFormat.Type = 3
        wordApp.Selection.ShapeRange.WrapFormat.Side = 3
        wordApp.Selection.ShapeRange.RelativeVerticalPosition = 0
        wordApp.Selection.ShapeRange.Left = -999995
        wordApp.Selection.ShapeRange.Top = -999995
    
        # 这里出问题了,提示没有select这个方法
        # wordApp.Selection.HeaderFooter.Shapes("0").Select
        # wordApp.Selection.ShapeRange.Duplicate.select
        # wordApp.Selection.ShapeRange.IncrementLeft(-426.8)
        # wordApp.Selection.ShapeRange.IncrementTop(403.85)
        # 关闭页眉页脚
        wordApp.ActiveWindow.ActivePane.View.SeekView = 0
        actDoc.Save()
        actDoc.Close()
        wordApp.Close()
    
    if __name__ == '__main__':
        getWordAddWatermark()
    
    
    展开全文
  • This will be a WordArt shape. // You are free to try other shape types as watermarks. Shape watermark =new Shape(doc, ShapeType.TextPlainText); // Set up the text of the watermark. watermark....
  • java实现word文档转pdf,并添加水印发布时间:2018-08-01 17:21,浏览次数:1115, 标签:javawordpdf前段时间,项目需要自动生成word文档,用WordFreeMarker生成word文档后,又要求生成的文档能在浏览器浏览,...
  • 废话不多说 直接上代码 public static void main(String[] args) throws Exception { String path= "d:\\xxx.doc"; InputStream input = new FileInputStream(path);... * 输入流,加水印后输出
  • winfrom给word加水印

    千次阅读 2015-07-14 11:16:17
    Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Open(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref ...
  • word 加水印C#

    千次阅读 2008-12-31 15:01:00
    private void responsewrite() { StringBuilder strscript = new StringBuilder(); strscript.Append(" /r/n"); strscript.Append("Set myDocApp = CreateObject(/"Word.
  • This will be a WordArt shape. // You are free to try other shape types as watermarks. Shape watermark = new Shape(doc, ShapeType.TextPlainText); // Set up the text of the watermark. watermark....
  • 如题 ,如何使用vc给word加上水印,最好有源代码或者详细的讲解。
  • 使用jacob的demo我在上一篇文章中已经做了笔记,接下来在这里我要记录jacob在web应用中的使用,同时也使用了itext为pdf添加水水印,框架为了方便使用的ssm框架。 搭建ssm框架这里就不做详细的介绍了,在我的博客中...
  • word加水印

    2010-12-14 11:36:00
    word加水印的宏代码:不是加载页眉或者页脚,是加在正文中,但是加在正文成功后,只能在当前页插入水印,如果实现每页都插入水印 Sub water()'' water 宏' 添加水印'ActiveDocument.Sections(1).Range.Select ...
  • word文档加水印

    2015-01-06 15:08:20
    word文档加水印,改示例是完整的demo示例。直接导入项目可以使用
  • iTextSharp简单生成pdf和操作pdf添加水印给word加水印,利用的是aspose.words
  • word批量加水印

    2020-12-06 17:28:16
    1、保存word格式为docx 2、更改文件后缀名为rar,提示是否更改选是 3、打开这个rar文件,在word-media文件夹可以看到word中的图片。。。 4、把这些图片解压到电脑上,给这些图片添加上水印,注意保存文件名不要更改 ...
  • word文档批量加水印工具,实现批量word文件加水印
  • word转pdf并加水印

    2017-08-21 10:05:24
    word转pdf并加水印示例
  • word文档加水印

    2019-10-03 02:48:51
    以前觉得在word里加个背景水印是件多么不可能的事情,不过呢,到今天才发现原来这只是个很简单的功能。发觉自己很“小样”!两种方法:一,在菜单栏中选“格式”----“背景”----“水印”就行了,在里面可以图片,...
  • 1、使用freemaker对模板解析填充数据导出word文档的功能 2、实现使用itext对word转pdf功能 3、实现了对pdf加水印功能
  • 批量加word水印页眉

    2013-03-30 14:09:42
    word大批量的添加页眉页脚和水印。包含多种水印模式,
  • 有个免费的第三方Free Spire.Doc for Java,操作Word文档的,支持水印功能,代码如下:1.文本水印importcom.spire.doc.*;importcom.spire.doc.documents.WatermarkLayout;importjava.awt.*;...
  • } }/*** 加水印方法 * *@paramdoc word文件流 *@paramwatermarkText 水印内容*/ public static voidinsertWatermarkText(Document doc, String watermarkText) {//居中 insertWatermarkText(doc, watermarkText, ...
  • 在办公的时候我们经常都会遇到要给文档加水印的情况,有时又会遇到从网上下载的文档有水印需要去掉的情况,水印这东西啊真是让人又爱又恨,不过别担心!不管你是想加水印还是想去水印,小编都能给你支几招!今天就给...

空空如也

空空如也

1 2 3 4 5 ... 17
收藏数 336
精华内容 134
关键字:

word加水印