1)首先pageoffice不能跨域访问
2)使用的是PageOffice_4.4.0.4_Java.zip
3)使用pageoffice不能随页面直接打开文件,只能通过前一个html打开
4)由于使用的是2个服务,因此pageoffice单独一个服务,只能通过磁盘路径访问
5)对路径进行了base64加密
6)
var croFilePath = "C:\\\\aaa"+filePath;croFilePath = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(croFilePath));
croFilePath = croFilePath.replace(/\+/g, "%2B");
由于使用了utf8的base64加密,因此java端也要进行utf-8的解密
var croFilePath = "D:\\\\pi-web-bncqk-1.0.0"+filePath;
croFilePath = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(croFilePath));
public static String encode(final byte[] bytes) {
return new String(org.apache.commons.codec.binary.Base64.encodeBase64(bytes));
}
public static byte[] decode(String payload) {
return org.apache.commons.codec.binary.Base64.decodeBase64(payload);
}
public static String encode(String source){
return encode(source.getBytes(Charset.forName("UTF-8")));
}
public static String decodeString(String payload) {
return new String( decode(payload),Charset.forName("UTF-8"));
}
public static String decodeUrl(String encodeurl){
try {
return java.net.URLDecoder.decode(encodeurl,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
public static String encodeUrl(String sourceUrl){
return java.net.URLEncoder.encode(sourceUrl);
}
7)由于base64加密有会有+号,+号在html中展示为空格,因此需要%2B转下
但是服务端依然会有空格,因此需要java把所有空格转换成+,因此上传的文件不能有空格
PageOfficeCtrl poCtrl=new PageOfficeCtrl(request);
WzBase64 wzBase64 = new WzBase64();
//设置服务器页面
poCtrl.setServerPage(request.getContextPath()+"/poserver.zz");
//添加自定义按钮
poCtrl.addCustomToolButton("全屏切换", "SwitchFullScreen()", 4);//全屏切换
//设置保存页面
poCtrl.setSaveFilePage("SaveFile.jsp");
//打开Word文档
String filePath = request.getParameter("filePath");
filePath = filePath.replaceAll(" ", "+");
poCtrl.webOpen( wzBase64.decodeString(filePath) ,OpenModeType.docReadOnly,"张佚名");