千家信息网

Pageoffice如何结合fastdfs在线编辑及预览office文档

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,本篇文章给大家分享的是有关Pageoffice如何结合fastdfs在线编辑及预览office文档,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来
千家信息网最后更新 2026年11月02日Pageoffice如何结合fastdfs在线编辑及预览office文档

本篇文章给大家分享的是有关Pageoffice如何结合fastdfs在线编辑及预览office文档,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

背景:我们项目的文档是存放在fastdfs服务器上面的,现有需求需要实现将fastdfs上面的各种office文档在网站页面进行预览和编辑保存

方案:由于fastdfs目前是不支持文档的更新的,所以只能通过插入新文档,删除老文档的方式来实现,同时需要将原有数据库表中存储的文件uuid给更新掉,然后pageoffice只能支持文档在本服务器内的预览和编辑,因此需要在应用服务器中先下载fastdfs服务器中的文件,然后本地保存为临时文件,然后给pageoffice预览编辑,保存后再通过删除和插入来更新fastdfs的文件,从而达到目的。

补充:需要定时清理由此产生的应用服务器下载的临时文件

大部分代码可以参考pageoffice官网文档中的

PageOffice 4.5 for JAVA (同时支持IE、Chrome、Firefox版)

PageOffice 4.5 for Spring Boot[示例代码]

放代码:

pageoffice初始配置类

@Configuration
public class PageOfficeConfiguration {

/**
* 添加PageOffice的服务器端授权程序Servlet(必须)
*/
@Bean
public ServletRegistrationBean servletRegistrationBean() {
com.zhuozhengsoft.pageoffice.poserver.Server poserver = new com.zhuozhengsoft.pageoffice.poserver.Server();
//设置PageOffice注册成功后,license.lic文件存放的目录
//服务器可以存放在/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;//
}
}

应用controller类

@Controller
@RequestMapping("/xx/pageoffice")
@Api(value = "文档在线编辑接口")
public class PageOfficeController {
@Value("${pageoffice.path.doc:'D:/doc/'}")
private String pageofficeDocPath;

@Autowired
private StorageService storageService;//fastdfs封装服务类
@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 = "业务代码")
@RequestParam(name = "busi", required = true) String busi,
@ApiParam(name = "filePath", required = true, value = "文件远程路径(相对路径,不是包含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 = "业务代码")
@RequestParam(name = "busi", required = false) String busi,
@ApiParam(name = "filePath", required = false, value = "文件远程路径(相对路径,不是包含http的全路径)")
@RequestParam(name = "filePath", required = false) String filePath){
String[] param = busi.split("%");//这里因为使用&符合传递多个参数时会导致被编译为&导致无法调用成功
busi = param[0];
filePath = param[2];
// pageofficeDocPath = "D:\\doc\\"; //本地开发环境时可使用
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("预览临时文件生成错误",e);
throw BusinessException.withErrorCode(Errors.System.ILLEAGAL_DATA);
}
//--- PageOffice的调用代码 开始 -----
PageOfficeCtrl poCtrl=new PageOfficeCtrl(request);
poCtrl.setServerPage("/xx/pageoffice/poserver.zz");//设置授权程序servlet
poCtrl.addCustomToolButton("保存","Save",1); //添加自定义按钮
poCtrl.setSaveFilePage("/xx/pageoffice/save?filePath="+filePath+"&busi="+busi+"&url="+url);//设置保存时的action
String prefix = "file://";//linux服务器查找文件需要额外前缀
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"));
//--- PageOffice的调用代码 结束 -----
ModelAndView mv = new ModelAndView("Word");
return mv;
}

@RequestMapping("/save")
public void saveFile(HttpServletRequest request, HttpServletResponse response,
@ApiParam(name = "busi", required = true, value = "业务代码")
@RequestParam(name = "busi", required = true) String busi,
@ApiParam(name = "url", required = false, value = "临时文件url")
@RequestParam(name = "url", required = false) String url,
@ApiParam(name = "filePath", required = true, value = "文件远程路径(相对路径,不是包含http的全路径)")
@RequestParam(name = "filePath", required = true) String filePath){
FileSaver fs = new FileSaver(request, response);
//由于fastdfs并不支持文件更新
//目前考虑删除原有的文件,重新生成文件
//TODO 后面可以考虑支持文件的更新,即框架来做删除插入,并且新插入的uuid需要跟删除的一致
String newCode = this.storageService.store(fs.getFileName(), fs.getFileStream());
//将原来业务表中的文档uuid更新
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预览准备



打开文件

Word.ftl




Hello World!




${pageoffice}


以上就是Pageoffice如何结合fastdfs在线编辑及预览office文档,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。

文件 文档 路径 服务 代码 服务器 更新 支持 业务 在线 应用 成功 同时 更多 知识 程序 篇文章 面的 生成 实用 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 西安纸贵互联网科技有限公司 互联网科技活动banner 互联网科技巨头监管 互联网金融公司科技 宜安科技 互联网金融 有木互联网科技 互联网科技论坛 互联网科技公司介绍 深圳卡尔迅互联网科技有限公司怎么样 新华互联网科技校企合作 顺网科技2021年互联网排名 深圳前海聚择互联网科技有限公司 北京华百购互联网科技有限公司 宁夏众和广鑫互联网科技有限公司 呼和浩特新华互联网科技学院 黑科技 体验场景 互联网大会 互联网相关科技技术 陕西云淼互联网科技公司 求路客互联网科技电话 科技互联网经济论坛 互联网科技公司排名 互联网为科技 融势互联网科技 互联网科技公司有风险吗 新兴科技互联网创新大赛颁奖典礼 健康食品互联网创新科技园项目 亳州好赞互联网科技有限公司 富国互联网金融科技混合基金 萌小萌互联网科技河南有限公司 容联科技互联网电商
0