PDF、WORD、EXCEL、PPT預覽
阿新 • • 發佈:2018-11-15
**
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(); }