|
@@ -1,5 +1,7 @@
|
|
|
package com.doc.biz.controller;
|
|
|
|
|
|
+import com.aspose.pdf.Document;
|
|
|
+import com.aspose.pdf.SaveFormat;
|
|
|
import com.doc.biz.domain.*;
|
|
|
import com.doc.biz.service.*;
|
|
|
import com.doc.biz.vo.DocumentVO;
|
|
@@ -17,12 +19,14 @@ import com.doc.common.utils.file.FileUtils;
|
|
|
import com.doc.common.utils.poi.ExcelUtil;
|
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.yaml.snakeyaml.util.UriEncoder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
@@ -198,8 +202,8 @@ public class DocInfoController extends BaseController {
|
|
|
@ApiOperation("文件重命名")
|
|
|
@GetMapping("/rename")
|
|
|
@Log(title = "文件基本信息表", businessType = BusinessType.UPDATE, eventLevel = EventLevel.MIDDLE)
|
|
|
- @ApiImplicitParams({@ApiImplicitParam(name = "docId", value = "文件ID", required = true,dataTypeClass = Long.class),
|
|
|
- @ApiImplicitParam(name = "name", value = "新文件名", required = true,dataTypeClass = Long.class)})
|
|
|
+ @ApiImplicitParams({@ApiImplicitParam(name = "docId", value = "文件ID", required = true, dataTypeClass = Long.class),
|
|
|
+ @ApiImplicitParam(name = "name", value = "新文件名", required = true, dataTypeClass = Long.class)})
|
|
|
public AjaxResult rename(Long docId, String name) {
|
|
|
DocInfo info = new DocInfo();
|
|
|
info.setDocId(docId);
|
|
@@ -388,15 +392,21 @@ public class DocInfoController extends BaseController {
|
|
|
@ApiOperation("pdf转word")
|
|
|
@Log(title = "文件基本信息表", businessType = BusinessType.INSERT, eventLevel = EventLevel.MIDDLE)
|
|
|
@PostMapping("/pdf2word")
|
|
|
- public ResponseEntity<Object> uploadFile(@ApiParam(value = "文件", required = true) @RequestPart(value = "file") MultipartFile file) {
|
|
|
- String disposition = "attachment; filename=\"" + UriEncoder.encode(file.getOriginalFilename()) + "\"";
|
|
|
- //TODO 未完
|
|
|
- return null;
|
|
|
-// return ResponseEntity.ok()
|
|
|
-// .header(HttpHeaders.CONTENT_DISPOSITION, disposition)
|
|
|
-// .header(HttpHeaders.CONTENT_TYPE, "docx")
|
|
|
-// .header(HttpHeaders.CONTENT_LENGTH, vo.getFileSize() + "")
|
|
|
-// .header("Connection", "close")
|
|
|
-// .body(vo.getData());
|
|
|
+ public void uploadFile(@ApiParam(value = "文件", required = true) @RequestPart(value = "file") MultipartFile file, HttpServletResponse response) {
|
|
|
+ long old = System.currentTimeMillis();
|
|
|
+ try (ServletOutputStream os = response.getOutputStream()) {
|
|
|
+ //doc是将要被转化的word文档
|
|
|
+ Document doc = new Document(file.getInputStream());
|
|
|
+ //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
|
|
|
+ doc.save(os, SaveFormat.DocX);
|
|
|
+ String disposition = "attachment; filename=\"" + UriEncoder.encode(file.getOriginalFilename()) + "\"";
|
|
|
+ response.addHeader(HttpHeaders.CONTENT_DISPOSITION, disposition);
|
|
|
+ //转化用时
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ logger.info("Pdf 转 Word 共耗时:" + ((now - old) / 1000.0) + "秒");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("Pdf 转 Word 失败...");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|