In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about Pageoffice how to combine fastdfs online editing and preview office documents, editor feel very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.
Background: the documents of our project are stored on the fastdfs server, and the existing requirements need to preview, edit and save all kinds of office documents on fastdfs on the website page.
Solution: since fastdfs currently does not support document updates, it can only be achieved by inserting new documents and deleting old documents. At the same time, the file uuid stored in the original database table needs to be updated, and then pageoffice can only support the preview and editing of documents in this server, so you need to download the file in the fastdfs server in the application server, then save it as a temporary file locally, and then preview and edit it for pageoffice. Save and then delete and insert to update the fastdfs file, so as to achieve the purpose.
Add: temporary files downloaded by the resulting application server need to be cleaned regularly
Most of the code can be found in the documentation on pageoffice's official website.
PageOffice 4.5 for JAVA (IE, Chrome, Firefox versions are also supported)
PageOffice 4.5 for Spring Boot [sample code]
Put the code:
Pageoffice initial configuration class
@ Configuration
Public class PageOfficeConfiguration {
/ * *
* add server-side authorization program Servlet for PageOffice (required)
, /
@ Bean
Public ServletRegistrationBean servletRegistrationBean () {
Com.zhuozhengsoft.pageoffice.poserver.Server poserver = new com.zhuozhengsoft.pageoffice.poserver.Server ()
/ / set the directory where the license.lic file is stored after PageOffice registration is successful
/ / the server can be stored in / geelyapp/pageoffice
Poserver.setSysPath ("d:\\ lic\")
ServletRegistrationBean srb = new ServletRegistrationBean (poserver)
Srb.addUrlMappings ("/ xx/pageoffice/poserver.zz")
Srb.addUrlMappings ("/ xx/pageoffice/posetup.exe")
Srb.addUrlMappings ("/ xx/pageoffice/pageoffice.js")
Srb.addUrlMappings ("/ xx/pageoffice/jquery.min.js")
Srb.addUrlMappings ("/ xx/pageoffice/pobstyle.css")
Srb.addUrlMappings ("/ xx/pageoffice/sealsetup.exe")
Return srb;//
}
}
Apply the controller class
@ Controller
@ RequestMapping ("/ xx/pageoffice")
@ Api (value = "document online editing interface")
Public class PageOfficeController {
@ Value ("${pageoffice.path.doc:'D:/doc/'}")
Private String pageofficeDocPath
@ Autowired
Private StorageService storageService;//fastdfs Encapsulation Service Class
@ Autowired
Private ICommonUtilService commonUtilService
Private static final Logger LOGGER = LoggerFactory.getLogger (PageOfficeController.class)
@ RequestMapping (value= "/ index", method=RequestMethod.GET)
Public ModelAndView showIndex (
@ ApiParam (name = "busi", required = true, value = "business code")
@ RequestParam (name = "busi", required = true) String busi
@ ApiParam (name = "filePath", required = true, value = "file remote path (relative path, not the full path containing http)")
@ RequestParam (name = "filePath", required = true) String filePath
Map map) {
Map.put ("busi", busi)
Map.put ("filePath", filePath)
ModelAndView mv = new ModelAndView ("Index")
Return mv
}
@ RequestMapping (value= "/ word", method=RequestMethod.GET)
Public ModelAndView showWord (HttpServletRequest request, Map map
@ ApiParam (name = "busi", required = false, value = "business code")
@ RequestParam (name = "busi", required = false) String busi
@ ApiParam (name = "filePath", required = false, value = "file remote path (relative path, not the full path containing http)")
RequestParam (name = "filePath", required = false) String filePath) {
String [] param = busi.split ("%"); / / here, the call cannot be successful because it is compiled to & when multiple parameters are passed using & match
Busi = param [0]
FilePath = param [2]
/ / pageofficeDocPath = "D:\\ doc\\"; / / available in the local development environment
String [] filePathArr = filePath.split ("/")
String url = pageofficeDocPath+ filePathArr [filePathArr.length-1]
LOGGER.info ("showWord url:" + url)
File tmpFile = new File (url)
Try (FileOutputStream fos = new FileOutputStream (tmpFile)) {
Fos.write (this.storageService.readFileContent (filePath))
} catch (Exception e) {
LOGGER.error ("Preview temporary file generation error", e)
Throw BusinessException.withErrorCode (Errors.System.ILLEAGAL_DATA)
}
/ /-the calling code of PageOffice starts-
PageOfficeCtrl poCtrl=new PageOfficeCtrl (request)
PoCtrl.setServerPage ("/ xx/pageoffice/poserver.zz"); / / set the authorization program servlet
PoCtrl.addCustomToolButton (Save, Save, 1); / / add a custom button
PoCtrl.setSaveFilePage ("/ xx/pageoffice/save?filePath=" + filePath+ "& busi=" + busi+ "& url=" + url); / / set the action when saving
String prefix = "additional prefix is required for file://";//linux server to find files
Url = prefix + url
LOGGER.info ("showWord pageoffice url:" + url)
If (filePath.endsWith (".doc") | | filePath.endsWith (".docx")) {
PoCtrl.webOpen (url,OpenModeType.docAdmin,SessionContextUtil.getSrmUserName ())
} else if (filePath.endsWith (".xls") | | filePath.endsWith (".xlsx")) {
PoCtrl.webOpen (url,OpenModeType.xlsNormalEdit,SessionContextUtil.getSrmUserName ())
} else if (filePath.endsWith (".ppt") | | filePath.endsWith (".pptx")) {
PoCtrl.webOpen (url,OpenModeType.pptNormalEdit,SessionContextUtil.getSrmUserName ())
}
Map.put ("pageoffice", poCtrl.getHtmlCode ("PageOfficeCtrl1"))
/ /-the end of the calling code of PageOffice
ModelAndView mv = new ModelAndView ("Word")
Return mv
}
@ RequestMapping ("/ save")
Public void saveFile (HttpServletRequest request, HttpServletResponse response
@ ApiParam (name = "busi", required = true, value = "business code")
@ RequestParam (name = "busi", required = true) String busi
@ ApiParam (name = "url", required = false, value = "temporary file url")
@ RequestParam (name = "url", required = false) String url
@ ApiParam (name = "filePath", required = true, value = "file remote path (relative path, not the full path containing http)")
RequestParam (name = "filePath", required = true) String filePath) {
FileSaver fs = new FileSaver (request, response)
/ / because fastdfs does not support file updates
/ / currently considering deleting the original file and regenerating the file
/ / after TODO, you can consider the update of the supporting file, that is, the frame is used to delete and insert, and the newly inserted uuid needs to be consistent with the deleted one.
String newCode = this.storageService.store (fs.getFileName (), fs.getFileStream ())
/ / update the document uuid in the original business table
CommonUtilService.updateFilePath (busi,filePath,newCode)
This.storageService.delete (filePath)
/ / fs.saveToFile (url)
Fs.close ()
File tmpFile = new File (url)
TmpFile.delete ()
}
}
Index.ftl
Index
PageOffice Preview preparation
Open a file
Word.ftl
Hello World!
Function Save () {
Document.getElementById (PageOfficeCtrl1) .WebSave ()
}
Function AddSeal () {
Try {
Document.getElementById (PageOfficeCtrl1) .ZoomSeal.AddSeal ()
} catch (e) {}
}
${pageoffice}
This is how Pageoffice combines fastdfs to edit and preview office documents online. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.