首页 > 其他分享 >用pageOffice控件实现 office word文档 编辑Word加水印的功能

用pageOffice控件实现 office word文档 编辑Word加水印的功能

时间:2022-12-23 11:35:51浏览次数:62  
标签:控件 word office doc 水印 pageOffice 文档 Word

OA办公中,业务需要多人编辑word文档,需要加文字水印的功能。

怎么实现word文档的编辑加文字水印呢?

2 实现方法

通过pageOffice实现简单的在线打开编辑word时,
通过设置doc.getWaterMark().setText("PageOffice开发平台"); 属性,给Word文档添加文字水印。
就可以实现编辑word中增加水印的功能

3 实现过程

以java的springboot框架为例

1 集成pageOffice

https://www.zhuozhengsoft.com/dowm/

image
从pageOffice官网
下载页面,找到springboot的集成示例,按照里面的集成明说,可以集成到自己的springboot项目中。

2 在线打开编辑word

image

可以按照这个示例首先实现最基本的打开word的方法。

3 通过代码实现编辑word中增加水印的功能

代码参考以下功能示例代码
image

control代码

点击查看代码
@RestController
@RequestMapping(value = "/AddWaterMark")
public class AddWaterMarkController {
    @RequestMapping(value = "/Word", method = RequestMethod.GET)
    public ModelAndView showWord(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.setServerPage(request.getContextPath() + "/poserver.zz");//设置服务页面

        WordDocument doc = new WordDocument();
        //添加水印 ,设置水印的内容
        doc.getWaterMark().setText("PageOffice开发平台");
        poCtrl.setWriter(doc);
        //打开Word文档
        poCtrl.webOpen("/doc/AddWaterMark/test.doc", OpenModeType.docNormalEdit, "张三");
        request.setAttribute("pageoffice", poCtrl.getHtmlCode("PageOfficeCtrl1"));
        ModelAndView mv = new ModelAndView("AddWaterMark/Word");
        return mv;
    }


}

 

html代码

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>添加水印</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
</head>
<body>
<!--**************   卓正 PageOffice组件 ************************-->
<div style=" width:auto; height:700px;" th:utext="${pageoffice}">
</div>
</body>
</html>

通过以上代码,可以实现编辑word中增加水印的功能

4效果图

image

文档打开后,直接显示设置的文字水印

5总结

用pageOffice控件实现 office word文档 编辑word中增加水印的功能

标签:控件,word,office,doc,水印,pageOffice,文档,Word
From: https://www.cnblogs.com/qingxue636/p/17000174.html

相关文章