Controller,引用到FileChangeUtils.java,PPTtoPDF.java
@ApiOperation("文件预览")
@GetMapping("/getShowFile/{id}")
@ApiImplicitParam(name = "id", value = "文件id", required = true)
public void getShowFile(HttpServletResponse response, @PathVariable("id") Long id) throws IOException{
DdsDocumentEntity info = ddsDocumentService.getById(id);
InputStream inputStream = null;
try {
ActionResult result = ossClient.presignedObjectUrl(id.toString());
List<PresignedObjectUrlDTO> list = (List<PresignedObjectUrlDTO>)result.getData();
if(list.size() > 0) {
PresignedObjectUrlDTO presignedObjectUrlDTO = list.get(0);
URL url = new URL(java.net.URLDecoder.decode(presignedObjectUrlDTO.getPresignedObjectUrl(), "UTF-8"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(3 * 1000);
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
inputStream = conn.getInputStream();
}
} catch (Exception e) {
log.error("文件不存在!" + e.getLocalizedMessage());
}
Assert.notNull(inputStream, "文件不存在!");
OutputStream os = response.getOutputStream();
try {
String suffix = info.getDocumentName().substring(info.getDocumentName().lastIndexOf(".") + 1);
if ("xls".equals(suffix) || "xlsx".equals(suffix)) {
FileChangeUtils.GetLicense("excel");
com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(inputStream);
PdfSaveOptions options = new PdfSaveOptions(SaveFormat.PDF);
options.setOnePagePerSheet(true);
wb.save(os, options);
} else if ("doc".equals(suffix) || "docx".equals(suffix)) {
FileChangeUtils.GetLicense("word");
com.aspose.words.Document doc = new com.aspose.words.Document(inputStream);
doc.save(os, com.aspose.words.SaveFormat.PDF);
} else if("ppt".equals(suffix) || "pptx".equals(suffix)){
new PPTtoPDF().convertPPTToPDF(inputStream,response.getOutputStream(),suffix);
} else if("pdf".equals(suffix)){
byte[] content = new byte[1024];
int length;
while ((length = inputStream.read(content,