Development environment: JDK 1.8, Eclipse, Sping Boot + Thymeleaf framework.
I. Projects to build the Sping Boot + Thymeleaf framework (no more details):
1. Create a new maven project project: demo.
2. Modify the pom.xml configuration and configure the project as a Spring Book project.
3. Configure Thymeleaf: Add Thymeleaf dependencies, and add Thymeleaf configuration in the application.properties file;
4. New DemoController, add showWord, showIndex methods:
@RequestMapping(value="/word", method=RequestMethod.GET) public ModelAndView showWord(HttpServletRequest request, Map<String,Object> map){ ModelAndView mv = new ModelAndView("Word"); return mv; } @RequestMapping(value="/index", method=RequestMethod.GET) public ModelAndView showIndex(){ ModelAndView mv = new ModelAndView("Index"); return mv; }
5. New Thymeleaf template page: Word.html, Index.html;
6. Run the demo project and access it successfully: http://localhost:8080/index
II. Integrated PageOffice
1. Adding PageOffice dependencies to pom.xml:
<! - Adding Sqlite dependencies (optional: if you don't need to use the Seal feature, you don't need to add this dependency)--> <dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> <version>3.7.2</version> </dependency> <! - Add PageOffice dependencies (must)--> <dependency> <groupId>com.zhuozhengsoft</groupId> <artifactId>pageoffice</artifactId> <version>4.3.0.2</version> </dependency>
2. Add two custom parameter configurations to the application.properties file, posyspath: specify a disk directory to store the license.lic file generated after successful registration of PageOffice; popassword: set the login password of PageOffice's own Seal Manager; for the server-side Servlet program of PageOffice to use:
######################################################## ###PageOffice ######################################################## posyspath=d:/lic/ popassword=111111
3. Add code to DemoController to get the two parameters defined in application.properties in the previous step:
@Value("${posyspath}") private String poSysPath; @Value("${popassword}") private String poPassWord;
4. Add the registration code of Servlet of PageOffice in DemoController:
/** * Servlet, a server-side authorization program that adds PageOffice (must) * @return */ @Bean public ServletRegistrationBean servletRegistrationBean() { com.zhuozhengsoft.pageoffice.poserver.Server poserver = new com.zhuozhengsoft.pageoffice.poserver.Server(); //Set up PageOffice After successful registration,license.lic A directory for storing documents. poserver.setSysPath(poSysPath); ServletRegistrationBean srb = new ServletRegistrationBean(poserver); srb.addUrlMappings("/poserver.zz"); srb.addUrlMappings("/posetup.exe"); srb.addUrlMappings("/pageoffice.js"); srb.addUrlMappings("/jquery.min.js"); srb.addUrlMappings("/pobstyle.css"); srb.addUrlMappings("/sealsetup.exe"); return srb; // }
5. Add the code to create the PageOffice Ctrl object in DemoController's showWord method. The first parameter of WebOpen method is the disk path of the office file on the server side. Temporarily use constant in demo: d:\\ test.doc.
@RequestMapping(value="/word", method=RequestMethod.GET) public ModelAndView showWord(HttpServletRequest request, Map<String,Object> map){ //--- PageOffice Call code to start ----- PageOfficeCtrl poCtrl=new PageOfficeCtrl(request); poCtrl.setServerPage("/poserver.zz");//Setting up Authorization Program servlet poCtrl.addCustomToolButton("Preservation","Save",1); //Add custom buttons poCtrl.setSaveFilePage("/save");//Setting saved action poCtrl.webOpen("d:\\test.doc",OpenModeType.docAdmin,"Zhang San"); map.put("pageoffice",poCtrl.getHtmlCode("PageOfficeCtrl1")); //--- PageOffice Call Code End ----- ModelAndView mv = new ModelAndView("Word"); return mv; }
6. Add the div and js code of the PageOffice client control in Word.html:
<div style="width:1000px;height:700px;" th:utext="${pageoffice}"> </div> <script type="text/javascript"> function Save() { document.getElementById("PageOfficeCtrl1").WebSave(); } </script>
7. Add references to pageoffice.js and jquery.min.js in Word.html, and add hyperlinks to open files:
<script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="pageoffice.js" id="po_js_main"></script> <a href="javascript:POBrowser.openWindowModeless('/word','width=1200px;height=800px;');">Open file</a>
8. Add saveFile method in DemoController to receive file stream uploaded by PageOffice client and save it to server specified disk directory. Temporarily use constant in DemoController: d:\\
@RequestMapping("/save") public void saveFile(HttpServletRequest request, HttpServletResponse response){ FileSaver fs = new FileSaver(request, response); fs.saveToFile("d:\\" + fs.getFileName()); fs.close(); }
9. Prepare a test.doc file (no 0 byte files) in the d-disk root directory for testing.
10. Run demo project, visit: http://localhost:8080/index Click on the hyperlink "Open Files" to open, edit and save files online.
3. Source code download
Download address: http://www.zhuozhengsoft.com/download/PageOffice 4.3.0.2 ForSpringBoot.zip