|
@@ -391,22 +391,39 @@ public class DocInfoController extends BaseController {
|
|
|
}
|
|
|
|
|
|
@ApiOperation("pdf转word")
|
|
|
- @Log(title = "文件基本信息表", businessType = BusinessType.INSERT, eventLevel = EventLevel.MIDDLE)
|
|
|
+ @Log(title = "PDF转WORD", businessType = BusinessType.INSERT, eventLevel = EventLevel.MIDDLE)
|
|
|
@PostMapping("/pdf2word")
|
|
|
- public void uploadFile(@ApiParam(value = "文件", required = true) @RequestPart(value = "file") MultipartFile file, HttpServletResponse response) {
|
|
|
- long old = System.currentTimeMillis();
|
|
|
- try (ServletOutputStream os = response.getOutputStream()) {
|
|
|
+ public void pdf2word(@ApiParam(value = "文件", required = true) @RequestPart(value = "file") MultipartFile file, HttpServletResponse response) {
|
|
|
+ try (ServletOutputStream os = response.getOutputStream(); Document doc = new Document(file.getInputStream());) {
|
|
|
//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) + "秒");
|
|
|
+ response.addHeader(HttpHeaders.CONTENT_TYPE, ".docx");
|
|
|
+ os.flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("Pdf 转 Word 失败{}", e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("pdf转word")
|
|
|
+ @Log(title = "PDF转WORD", businessType = BusinessType.INSERT, eventLevel = EventLevel.MIDDLE)
|
|
|
+ @GetMapping("/pdf2word/{fileId}")
|
|
|
+ public void pdf2word(@PathVariable(name = "fileId") String fileId, HttpServletResponse response) {
|
|
|
+ DocumentVO vo = mongoService.downloadFile(fileId);
|
|
|
+ try (ServletOutputStream os = response.getOutputStream(); Document doc = new Document(vo.getData());) {
|
|
|
+ //doc是将要被转化的word文档
|
|
|
+ //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
|
|
|
+ doc.save(os, SaveFormat.DocX);
|
|
|
+ String disposition = "attachment; filename=\"" + UriEncoder.encode(vo.getFileName()) + "\"";
|
|
|
+ response.addHeader(HttpHeaders.CONTENT_DISPOSITION, disposition);
|
|
|
+ response.addHeader(HttpHeaders.CONTENT_TYPE, ".docx");
|
|
|
+ os.flush();
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("Pdf 转 Word 失败...");
|
|
|
+ logger.error("Pdf 转 Word 失败{}", e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|