|
@@ -5,7 +5,10 @@
|
|
|
|
|
|
package com.minto.web.td;
|
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
import com.documents4j.api.DocumentType;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.minto.app.tc.knowledge.enums.KmEnum;
|
|
|
import com.minto.app.tc.knowledge.manager.IKnowledgeManager;
|
|
@@ -18,6 +21,7 @@ import com.minto.app.space.util.SpaceFileUtil;
|
|
|
import com.minto.app.td.base.beans.http.ResponseBean;
|
|
|
import com.minto.app.td.base.manager.ITdBaseManager;
|
|
|
import com.minto.core.common.SystemEnvironment;
|
|
|
+import com.minto.core.common.SystemProperties;
|
|
|
import com.minto.td.token.ITokenProcessorManager;
|
|
|
import com.minto.app.td.base.util.TDUtil;
|
|
|
import com.minto.td.token.TokenProcessor;
|
|
@@ -775,49 +779,46 @@ public class TdFileController extends TdBaseController {
|
|
|
@ResponseBody
|
|
|
@Operation(summary = "word 转 pdf ")
|
|
|
@GetMapping("/showWord")
|
|
|
- public ModelAndView showWord(HttpServletRequest request, HttpServletResponse response)
|
|
|
- throws BusinessException{
|
|
|
- InputStream is = null;
|
|
|
- try{
|
|
|
- ISpaceManager manager = AppContext.getBean(ISpaceManager.class);
|
|
|
- String fileId = ReqUtil.getString(request, "fileId");
|
|
|
- if(StringUtil.isNotEmpty(fileId)){
|
|
|
- Long fid = takeFileId(fileId);//得到文件id
|
|
|
- SpaceFileBO bo = manager.findSpaceFileBO(fid);
|
|
|
- String wordFilePath = bo.getFile().getPath();
|
|
|
- String fileName = bo.getSpaceFileBean().getFileName()
|
|
|
- .replace(bo.getSpaceFileBean().getFileType(), "pdf");
|
|
|
- String pdfFilePath = wordFilePath.replace(fileId, fileName);
|
|
|
- String fileType = bo.getSpaceFileBean().getFileType();
|
|
|
- if("docx".equals(fileType)){
|
|
|
- Docx4jOfficeFileToPDF.docxToPdf(wordFilePath, pdfFilePath, DocumentType.DOCX);
|
|
|
- } else if("doc".equals(fileType)){
|
|
|
- Docx4jOfficeFileToPDF.docxToPdf(wordFilePath, pdfFilePath, DocumentType.DOC);
|
|
|
- } else if("xlsx".equals(fileType)){
|
|
|
- Docx4jOfficeFileToPDF.xlsxToPdf(wordFilePath, pdfFilePath, DocumentType.XLSX);
|
|
|
- } else if("xls".equals(fileType)){
|
|
|
- Docx4jOfficeFileToPDF.xlsxToPdf(wordFilePath, pdfFilePath, DocumentType.XLS);
|
|
|
- } else if("pptx".equals(fileType) || "ppt".equals(fileType)){
|
|
|
- Docx4jOfficeFileToPDF.pptToPdf(bo.getFile(), wordFilePath, pdfFilePath);
|
|
|
- }else if("pdf".equals(fileType)){
|
|
|
- pdfFilePath = bo.getFile().getPath();
|
|
|
- }
|
|
|
- //获取到的转换后的pdf路径
|
|
|
- File previewFile = new File(pdfFilePath);
|
|
|
- is = new FileInputStream(previewFile);
|
|
|
- response.setContentType(SpaceEnum.MimeTypeEnum.pdf.getDes());
|
|
|
- response.setHeader("Content-disposition",
|
|
|
- "inline;filename=\"" + URLEncoder.encode(fileName, StandardCharsets.UTF_8) + "\"");
|
|
|
- SystemUtil.writeStream(is, response.getOutputStream());
|
|
|
- }
|
|
|
- } catch(Exception e){
|
|
|
- log.error(ExceptionUtil.printExceptionStackTrace(e));
|
|
|
+ public void showWord(HttpServletRequest request, HttpServletResponse response) throws IOException{
|
|
|
+ List<String> onShowTypes = Lists.newArrayList();
|
|
|
+ onShowTypes.addAll(Arrays.asList(KmEnum.ArcSummaryTypeEnum.Excel.getFtype().split(",")));
|
|
|
+ onShowTypes.addAll(Arrays.asList(KmEnum.ArcSummaryTypeEnum.Word.getFtype().split(",")));
|
|
|
+ onShowTypes.addAll(Arrays.asList(KmEnum.ArcSummaryTypeEnum.PPT.getFtype().split(",")));
|
|
|
+ onShowTypes.addAll(Arrays.asList(KmEnum.ArcSummaryTypeEnum.Pdf.getFtype().split(",")));
|
|
|
|
|
|
- } finally{
|
|
|
- if(is != null){
|
|
|
- SystemUtil.closeAll(is);
|
|
|
- }
|
|
|
+
|
|
|
+ ISpaceManager manager = AppContext.getBean(ISpaceManager.class);
|
|
|
+ String fileId = ReqUtil.getString(request, "fileId");
|
|
|
+ if(StringUtil.isEmpty(fileId)){
|
|
|
+ return;
|
|
|
}
|
|
|
- return null;
|
|
|
+ //得到文件id
|
|
|
+ Long fid = takeFileId(fileId);
|
|
|
+ SpaceFileBO bo = manager.findSpaceFileBO(fid);
|
|
|
+ String wordFilePath = bo.getFile().getPath();
|
|
|
+ String fileName = bo.getSpaceFileBean().getFileName().replace(bo.getSpaceFileBean().getFileType(), "pdf");
|
|
|
+ String pdfFilePath = wordFilePath.replace(fileId, fileName);
|
|
|
+ String fileType = bo.getSpaceFileBean().getFileType();
|
|
|
+ if(!onShowTypes.contains(fileType)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(KmEnum.ArcSummaryTypeEnum.Pdf.getFtype().contains(fileType)){
|
|
|
+ response.setContentType(SpaceEnum.MimeTypeEnum.pdf.getDes());
|
|
|
+ response.setHeader("Content-disposition",
|
|
|
+ "inline;filename=\"" + URLEncoder.encode(fileName, StandardCharsets.UTF_8) + "\"");
|
|
|
+ SystemUtil.writeStream(bo.getStreamable().openInputStream(), response.getOutputStream());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String url = SystemProperties.getInstance().getProperty("officeOnlineShow.url");
|
|
|
+ if(StringUtil.isNotEmpty(url)){
|
|
|
+ // 发送POST请求并携带文件
|
|
|
+ HttpResponse res =
|
|
|
+ HttpRequest.post(url + "/apis/office/toPdf").form("file", bo.getFile()).form("fileType", fileType).execute();
|
|
|
+ response.setContentType(SpaceEnum.MimeTypeEnum.pdf.getDes());
|
|
|
+ response.setHeader("Content-disposition",
|
|
|
+ "inline;filename=\"" + URLEncoder.encode(fileName, StandardCharsets.UTF_8) + "\"");
|
|
|
+ SystemUtil.writeStream(res.bodyStream(), response.getOutputStream());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|