首先需要下载pageoffice的jar包,以及客户端的安装程序,如下图所示:
并且将这四个放在对应的lib目录下面,在web.xml中也要进行相应的添加,代码如下(一下所示的代码均来自于pageoffice官方代码,只是补充了一些自己的见解):
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.5"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>
- org.apache.struts2.dispatcher.FilterDispatcher
- </filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>*.action</url-pattern>
- </filter-mapping>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>*.jsp</url-pattern>
- </filter-mapping>
- <!-- PageOffice Begin -->
- <servlet>
- <servlet-name>poserver</servlet-name>
- <servlet-class>com.zhuozhengsoft.pageoffice.poserver.Server</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>poserver</servlet-name>
- <url-pattern>/poserver.do</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>poserver</servlet-name>
- <url-pattern>/pageoffice.cab</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>poserver</servlet-name>
- <url-pattern>/popdf.cab</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>poserver</servlet-name>
- <url-pattern>/sealsetup.exe</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>poserver</servlet-name>
- <url-pattern>/posetup.exe</url-pattern>
- </servlet-mapping>
- <servlet>
- <servlet-name>adminseal</servlet-name>
- <servlet-class>com.zhuozhengsoft.pageoffice.poserver.AdminSeal</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>adminseal</servlet-name>
- <url-pattern>/adminseal.do</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>adminseal</servlet-name>
- <url-pattern>/loginseal.do</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>adminseal</servlet-name>
- <url-pattern>/sealimage.do</url-pattern>
- </servlet-mapping>
- <mime-mapping>
- <extension>mht</extension>
- <mime-type>message/rfc822</mime-type>
- </mime-mapping>
- <context-param>
- <param-name>adminseal-password</param-name>
- <param-value>123456</param-value>
- </context-param>
- <!--<context-param>
- <param-name>posealdb-driver</param-name>
- <param-value>com.mysql.jdbc.Driver</param-value>
- </context-param>
- <context-param>
- <param-name>posealdb-url</param-name>
- <param-value>jdbc:mysql://localhost:3306/sample</param-value>
- </context-param>
- <context-param>
- <param-name>posealdb-username</param-name>
- <param-value>root</param-value>
- </context-param>
- <context-param>
- <param-name>posealdb-password</param-name>
- <param-value>admin</param-value>
- </context-param>-->
- <!-- PageOffice End -->
- </web-app>
在action的类中必须实现ServletRequestAware, ServletResponseAware两个接口,实现setServletRequest和setServletResponse方法,并且声明一个HttpServletRequest和HttpServletResponse和message(可写,返回客户端的消息),并且将声明的值注入到对应的set方法中
利用pageoffice打开对应的文档的操作是:
- public String openword() throws Exception {
- PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(ServletActionContext.getRequest());//获取pageoffice对象
- poCtrl1.setServerPage("poserver.do"); //此行必须
- // Create custom toolbar
- poCtrl1.addCustomToolButton("保存", "SaveDocuments()", 1);//SaveDocuments与jsp页面中的js函数名字一致,数字代表的是对应的图标
- poCtrl1.addCustomToolButton("-", "", 0);
- poCtrl1.addCustomToolButton("打印", "ShowPrintDlg()", 6);
- poCtrl1.addCustomToolButton("-", "", 0);
- poCtrl1.addCustomToolButton("全屏切换", "SetFullScreen()", 4);
- poCtrl1.addCustomToolButton("-", "", 0);
- poCtrl1.addCustomToolButton("加盖印章", "AddSeal()", 5);
- poCtrl1.addCustomToolButton("手写签批", "AddHandSign()", 5);
- poCtrl1.addCustomToolButton("验证印章", "VerifySeal()", 5);
- poCtrl1.setSaveFilePage("saveword.action");//保存需要执行的的action
- poCtrl1.webOpen("doc/test.doc", OpenModeType.docNormalEdit, "张三");//需要打开的打开的文档
- poCtrl1.setTagId("PageOfficeCtrl1"); //此行必须和前端中的<po:PageOfficeCtrl id="PageOfficeCtrl1" />id保持一致
- return "openword_"+SUCCESS;
- }
利用pageoffice保存文档的操作是:
- public String saveword() throws Exception {
- FileSaver fs = new FileSaver(request, response);
- request.setAttribute("FileSaver", fs);//FileSaver位苦丁的字符串
- fs.saveToFile(request.getSession().getServletContext().getRealPath("doc/") + "/" + fs.getFileName());
- fs.showPage(300, 300);
- message = "结果保存成功!";
- return "saveword_"+SUCCESS;
- }
客户端的代码:
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%@ taglib prefix="s" uri="/struts-tags"%>
- <%@ taglib uri="http://java.pageoffice.cn" prefix="po"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>My JSP 'editword.jsp' starting page</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 客户端代码开始 ************************-->
- <script language="javascript" type="text/javascript">
- function SaveDocuments() {
- document.getElementById("PageOfficeCtrl1").WebSave();
- //alert(document.getElementById("PageOfficeCtrl1").CustomSaveResult);
- }
- function ShowPrintDlg() {
- document.getElementById("PageOfficeCtrl1").ShowDialog(4);
- }
- function SetFullScreen() {
- document.getElementById("PageOfficeCtrl1").FullScreen = !document.getElementById("PageOfficeCtrl1").FullScreen;
- }
- function AddSeal() {
- document.getElementById("PageOfficeCtrl1").ZoomSeal.AddSeal();
- }
- function AddHandSign() {
- document.getElementById("PageOfficeCtrl1").ZoomSeal.AddHandSign();
- }
- function VerifySeal() {
- try
- {
- document.getElementById("PageOfficeCtrl1").ZoomSeal.VerifySeal();
- }
- catch(e)
- {
- }
- }
- </script>
- <!--************** 卓正 PageOffice 客户端代码结束 ************************-->
- <!-- <div style="width:auto;height:200px;background-color: gray">
- </div> -->
- <div style="width:auto; height:600px;">
- <po:PageOfficeCtrl id="PageOfficeCtrl1" />
- </div>
- </body>
- </html>
本文含有隐藏内容,请 开通VIP 后查看