修改基线保存
This commit is contained in:
+53
@@ -766,5 +766,58 @@ public class OnlyOfficeController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "|File|在线编辑下载docx文件")
|
||||||
|
@GetMapping("/onlyOfficeDownloadDocxFileTwo")
|
||||||
|
public void onlyOfficeDownloadDocxFileTwo(String fileId, HttpServletResponse response, HttpServletRequest request) {
|
||||||
|
OSSFile ossFile = ossFileService.getById(fileId);
|
||||||
|
if (ObjectUtils.isNotEmpty(ossFile)) {
|
||||||
|
InputStream is = null;
|
||||||
|
OutputStream os = null;
|
||||||
|
response.reset();
|
||||||
|
try {
|
||||||
|
String fileOldName = fileNameEncoding(ossFile.getFileName(), request);
|
||||||
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=\"" + fileOldName + "\"");
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
|
||||||
|
// 加载文档
|
||||||
|
Document doc = new Document(ossFile.getUrl());
|
||||||
|
doc.getSections().get(0).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
|
||||||
|
doc.getSections().get(0).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||||
|
doc.getSections().get(1).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||||
|
|
||||||
|
String downloadDocxFileTempUrl = filePath + "/downloadDocxFileTemp";
|
||||||
|
File downloadDocxFileTempUrlFile = new File(downloadDocxFileTempUrl);
|
||||||
|
|
||||||
|
if (!downloadDocxFileTempUrlFile.exists()) {
|
||||||
|
downloadDocxFileTempUrlFile.mkdirs();
|
||||||
|
}
|
||||||
|
String newFileName = UUID.randomUUID().toString().replace("-", "") + ".docx";
|
||||||
|
String newFileUrl = downloadDocxFileTempUrl + "/" + newFileName;
|
||||||
|
|
||||||
|
//保存文档
|
||||||
|
doc.saveToFile(newFileUrl);
|
||||||
|
|
||||||
|
File newFile = new File(newFileUrl);
|
||||||
|
is = new FileInputStream(newFile);
|
||||||
|
os = response.getOutputStream();
|
||||||
|
IOUtils.copy(is, os);
|
||||||
|
os.flush();
|
||||||
|
|
||||||
|
is.close();
|
||||||
|
if (newFile.delete()) {
|
||||||
|
logger.info("在线编辑下载-临时文件删除成功: " + newFileUrl);
|
||||||
|
} else {
|
||||||
|
logger.info("在线编辑下载-临时文件删除失败: " + newFileUrl);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(is);
|
||||||
|
IOUtils.closeQuietly(os);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user