**
PDF、WORD、EXCEL、PPT预览
**
-
前台页面
- 获取fileType(文件类型)、key(文件id)、title(文件标题)、url(文件路径)、documentType(不同的文件格式对应的值不同,后台代码中会有,传到前台即可)5个值到页面即可
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<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">
</head>
<body>
<div id="placeholder"></div>
</body>
<script type="text/javascript" src="http://10.41.215.164:9000/web-apps/apps/api/documents/api.js"></script>
<script type="text/javascript">
var _data=parent.window.fdata.display_data;
var config = {
"document": {
"fileType": _data.fileType,
"key": _data.key,
"title": _data.title,
"url": _data.url
},
"documentType": _data.documentType,
"editorConfig": {
"mode": "view",
"lang": "zh-CN",
"customization": {
"chat": false,
"help": false
}
}
};
var docEditor = new DocsAPI.DocEditor("placeholder", config);
</script>
</html>
@RequestMapping(value = "/displaypdf", method = RequestMethod.POST)
@ResponseBody
public String displayPdf(HttpServletRequest request, HttpServletResponse response) {
JSONObject result=new JSONObject();
String fileid = request.getParameter("fileid");
String filepath = request.getParameter("filepath");
String filename = request.getParameter("filename");
String prefix = filename.substring(
filename.lastIndexOf(".") + 1).toLowerCase();
String doctype = "";
String pagetype = "document";
if ("doc,docm,docx,dot,dotm,dotx,epub,fodt,htm,html,mht,odt,ott,pdf,rtf,txt,djvu,xps".indexOf(prefix) > -1) {
log.info("doc,docm,docx,dot,dotm,dotx,epub,fodt,htm,html,mht,odt,ott,pdf,rtf,txt,djvu,xps.indexOf(prefix) > -1");
doctype = "text";
pagetype = "document";
} else if ("csv,fods,ods,ots,xls,xlsm,xlsx,xlt,xltm,xltx".indexOf(prefix) > -1) {
log.info("csv,fods,ods,ots,xls,xlsm,xlsx,xlt,xltm,xltx.indexOf(prefix) > -1");
doctype = "spreadsheet";
pagetype = "document";
} else if ("fodp,odp,otp,pot,potm,potx,pps,ppsm,ppsx,ppt,pptm,pptx".indexOf(prefix) > -1) {
log.info("fodp,odp,otp,pot,potm,potx,pps,ppsm,ppsx,ppt,pptm,pptx.indexOf(prefix) > -1");
doctype = "presentation";
pagetype = "document";
} else {
log.info("不支持此类文件预览查看");
throw new RuntimeException("不支持此类文件预览查看");
}
String url="http://"+ftpip+":8088"+filepath;
result.put("fileType", prefix);
result.put("key", fileid);
result.put("title", filename);
result.put("url", url);
result.put("documentType", doctype);
return result.toJSONString();
}