当前位置: 首页 > news >正文

合肥大型网站北京网站制作公司兴田德润实力强

合肥大型网站,北京网站制作公司兴田德润实力强,常见的服务器有哪些,自己做的网站360显示过期此项目根据企业真实需求制作而成#xff0c;希望能帮助大家解决在线预览的问题#xff01; 此项目已开源#xff0c;欢迎大家来STAR 软件版本SpringBoot2.2.2.RELEASELibreOffice6.3.2unoconv0.6文章目录一、配置管理① pom② yml③ controller④ 文件格式转换工具类FileFor… 此项目根据企业真实需求制作而成希望能帮助大家解决在线预览的问题 此项目已开源欢迎大家来STAR 软件版本SpringBoot2.2.2.RELEASELibreOffice6.3.2unoconv0.6文章目录一、配置管理① pom② yml③ controller④ 文件格式转换工具类FileFormatConverToPDF⑤ 在线预览previewPDFUtils⑥ 启动类二、测试验证①测试链接②测试效果三、安装Unoconv①yum安装Unoconv②源码安装Unoconv四、安装LibreOffice一、配置管理 ① pom ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.2.2.RELEASE/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.gblfy/groupIdartifactIdbusiness-online-preview/artifactIdversion0.0.1-SNAPSHOT/versionnamebusiness-online-preview/nameurlhttps://gblfy.com/urldescription在线预览/descriptionpropertiesjava.version1.8/java.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.apache.poi/groupIdartifactIdpoi/artifactIdversion4.0.0/version/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build/project ② yml 空 ③ controller package com.gblfy.onlinepreview.controller;import com.gblfy.onlinepreview.utils.FileFormatConverToPDF; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletResponse;/*** author gblfy* ClassNme FileController* Description 文件在在线预览* Date 2020/01/08 8:09* version1.0*/ RestController public class FileOnlinePreviewController {/*** 在线预览测试方法* 企业真实需求:* 文件的路径 文件名 都需要动态获取** param response http响应网页来实现在线预览* throws Exception*/RequestMapping(/viewPDF)public void reviewWord(HttpServletResponse response) throws Exception {FileFormatConverToPDF linuxPageDIsplsyFileUtil new FileFormatConverToPDF();//文件存储路径String fileStoragePath /app/ftpFileDir/testFileDir/businessLearning/;//转换前的文件名String beforeConversion 知识库建设方案2019-11-11.docx;/*** 文件格式转换在线预览*/linuxPageDIsplsyFileUtil.conversionFile(response, fileStoragePath, beforeConversion);} } ④ 文件格式转换工具类FileFormatConverToPDF package com.gblfy.onlinepreview.utils;import lombok.extern.slf4j.Slf4j; import org.apache.poi.util.IOUtils;import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.ArrayList; import java.util.List;/*** Author:* Date: 2019/1/15 0015 15:04* describe 文档在线预览 (服务器环境为Linux环境) 目前文档类型 仅开放 Excel 03/07 word 03/07 ppt 03/07*/ Slf4j public class FileFormatConverToPDF {//libreoffice 文件格式转换shell命令public static final String LIBREOFFICE_SHELLCMD /usr/bin/soffice --headless --invisible --convert-to pdf ;//unoconv 文件格式转换shell命令public static final String UNOCONV_SHELLCMD /usr/bin/unoconv -f pdf ;//previewfile_dir 需要预览的pdf目录public static final String PREVIEWFILE_DIR /root/;private static FileFormatConverToPDF linuxPageDIsplsyFileUtil;public static synchronized FileFormatConverToPDF getSwitchUtil() {if (linuxPageDIsplsyFileUtil null) {linuxPageDIsplsyFileUtil new FileFormatConverToPDF();}return linuxPageDIsplsyFileUtil;}/*** 文档在线预览** param response* param fileStoragePath 文件存储路径 (前段获取文件存储路径返给后台)* param beforeConversion 文件名(必须带文件后缀名这里指的就是文件全名称)* throws Exception*/public void conversionFile(HttpServletResponse response, String fileStoragePath, String beforeConversion) throws Exception {String fileNamePath fileStoragePath beforeConversion;log.info(文件路径 fileNamePath);File file new File(fileNamePath);if (!file.exists()) {log.info(库存中没有指定文件。。。。);return;}//获取到文件名String interceptFileName beforeConversion.substring(0, beforeConversion.lastIndexOf(.));//截取文件后缀名String fileNameSuffix beforeConversion.substring(beforeConversion.lastIndexOf(.) 1);String command null;System.out.println(获取到文件名 interceptFileName);System.out.println(截取文件后缀名 fileNameSuffix);if (doc.equals(fileNameSuffix)|| docx.equals(fileNameSuffix)|| xls.equals(fileNameSuffix)|| xlsx.equals(fileNameSuffix)|| ppt.equals(fileNameSuffix)|| pptx.equals(fileNameSuffix)) {System.out.println(此文件属于 fileNameSuffix 开始进行转换);command LIBREOFFICE_SHELLCMD fileNamePath;executeLinuxCmd(command);} else {command UNOCONV_SHELLCMD fileNamePath;executeCommand(command);}System.out.println(openPDF的参数 fileStoragePath interceptFileName);previewPDFUtils.openPdf(response, PREVIEWFILE_DIR interceptFileName .pdf);}/*** 使用LibreOffice进行格式转换 to pdf** param cmd* return* throws IOException*/public static ListString executeLinuxCmd(String cmd) throws IOException {log.info(执行文件转换的命令: cmd);Runtime run Runtime.getRuntime();Process process run.exec(new String[]{/bin/sh, -c, cmd});InputStream in process.getInputStream();BufferedReader bs new BufferedReader(new InputStreamReader(in));ListString list new ArrayListString();String result null;while ((result bs.readLine()) ! null) {log.info(job result [ result ]);list.add(result);}in.close();process.destroy();return list;}/*** 使用Unoconv进行格式转换 to pdf** param command* throws Exception*/private static void executeCommand(String command) throws Exception {log.info(执行文件转换的命令: command);StringBuffer output new StringBuffer();Process process;InputStreamReader inputStreamReader null;BufferedReader reader null;try {process Runtime.getRuntime().exec(command);process.waitFor();inputStreamReader new InputStreamReader(process.getInputStream(), UTF-8);reader new BufferedReader(inputStreamReader);String line ;while ((line reader.readLine()) ! null) {output.append(line \n);}//p.destroy();//这个一般不需要} catch (Exception e) {e.printStackTrace();} finally {IOUtils.closeQuietly(reader);IOUtils.closeQuietly(inputStreamReader);}} }⑤ 在线预览previewPDFUtils package com.gblfy.onlinepreview.utils;import javax.servlet.http.HttpServletResponse; import java.io.FileInputStream; import java.io.InputStream; import java.io.OutputStream;/*** author gblfy* ClassNme previewPDF* Description TODO* Date 2020/1/8 12:47* version1.0*/ public class previewPDFUtils {/*** 在线预览pdf文件** param response* param previewFile 预览pdf文件的绝对路径* throws Exception*/public static void openPdf(HttpServletResponse response, String previewFile) throws Exception {InputStream inputStream null;OutputStream outputStream null;System.out.println(进入openPDF previewFile);//String path /home/tubiao/桌面/优化数据库.pdf;inputStream new FileInputStream(previewFile);response.setContentType(application/pdf);outputStream response.getOutputStream();int a 0;byte[] b new byte[1024];while ((a inputStream.read(b)) ! -1) {outputStream.write(b, 0, a);}if (outputStream ! null) {outputStream.close();}if (inputStream ! null) {inputStream.close();}} }⑥ 启动类 package com.gblfy.onlinepreview;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;/*** 在线预览统一入口*/ SpringBootApplication public class OnlinePreviewApplication {public static void main(String[] args) {SpringApplication.run(OnlinePreviewApplication.class, args);System.out.println(启动成功);} }二、测试验证 ①测试链接 浏览器测试链接http://localhost:8888/viewPDF ②测试效果 三、安装Unoconv ①yum安装Unoconv unoconv 在线预览 docdoxcxlsxlsxpptpptx 文件功能环境搭建 https://gblfy.blog.csdn.net/article/details/102847276 ②源码安装Unoconv 企业内部Linux环境_源码安装Unoconv实现文件在线预览docdoxcxlsxlsxpptpptx 文件 https://gblfy.blog.csdn.net/article/details/103540694 四、安装LibreOffice 企业内部Linux环境_源码安装LibreOffice实现文件在线预览docdoxcxlsxlsxpptpptx 文件 https://gblfy.blog.csdn.net/article/details/103861905 友情链接 (企业内部)SpringBoot 使用LibreOffice 在线预览 docdoxcxlsxlsxpptpptx 文件 https://gblfy.blog.csdn.net/article/details/103861607
http://www.yutouwan.com/news/400910/

相关文章:

  • 驻马店 网站制作短视频代运营费用明细
  • 网站关键词筛选域名注册网站哪个好
  • 帮做钓鱼网站会怎样成都游戏网站建设
  • 柳州房地产网站建设一般企业邮箱是哪里注册
  • 做网站 怎么推广dw wordpress
  • 深圳宝安区哪里好玩班级优化大师下载
  • 社区网站 备案做项目的网站
  • 培训通网站建设宁波北京网站建设
  • 携程网建设网站的理由交互设计产品有哪些
  • 网站怎么更改后台登陆密码网站设计中的事件是什么
  • 用ip地址做网站网站建设 台州
  • 分享网站模板信和财富网站开发
  • 网站开发合同 doc怎么自己做视频网站
  • 网站开发就业培训班免费红色ppt模板下载
  • 品牌网站建设的意义网站建设常规尺寸
  • 老徐蜂了网站策划书北京网络优化公司
  • 建站哪家好 discuz郑州那家做网站便宜
  • 网站关键字 怎么设置网站建设研究方法
  • 莆田建设局网站wordpress新建字段
  • 课程微网站开发技术wordpress4.4.1
  • 简述织梦网站上传步骤有什么做公众号封面图的网站
  • 做毕业设计哪个网站好应用软件开发包括什么
  • 松江外贸网站建设WordPress恶意扫描
  • 正在建设中的网站可算违规阿里云域名
  • 网站开发需要的软件德尔普网络做网站怎么样
  • 宿迁市建设局网站360建筑网怎么找回密码
  • 个人网站建设的流程怎么用dw做可上传文件的网站
  • 网站需求分市场推广渠道有哪些
  • 网站设计目标与背景互联网网站如何做流量统计
  • 推荐昆明做网站建设怎么仿别人的网站