@Controller
@RequestMapping("manage")
public class UploadController extends BaseController {
@Autowired
AttachmentService attachmentService;
@Value("${ATTACHMENT_UPLOAD_PATH:/manage-master/manage-upload/}")
private String uploadPath;
@Value("${HAS_WATERMARK:内部使用}")
private String watermark;
@Autowired
private ConfigService configService;
@RequestMapping("preview/{id}")
@ResponseBody
@RequiresAuthentication
public ResponseData preview(@PathVariable("id") String id, HttpServletResponse response, HttpServletRequest request) throws Exception {
//Attachment attachment = attachmentService.selectByPrimaryKey(id);
String suffix = ".docx";
String pdfPath = "D://upload/attached/20201204/test.pdf";
String filePath = "D://upload/attached/20201204/test" + suffix;
try {
//如果原始文件为pdf,则查询pdf
if (pdfPath.equals(filePath)) {
pdfPath = pdfPath.replace(".pdf", "_water.pdf");
}
File file = new File(pdfPath);
if (!file.exists()) {
//通过系统配置表拿水印参数,如果有,使用系统配置表参数,
// 如果没有,则使用原有项目配置文件配置
if (".xls".equalsIgnoreCase(suffix) || ".xlsx".equalsIgnoreCase(suffix)) {
OfficeUtil.excelToPdfWithWater(filePath, pdfPath, false, watermark);
}
if (".doc".equalsIgnoreCase(suffix) || ".docx".equalsIgnoreCase(suffix)) {
OfficeUtil.docToPdfWithWater(filePath, pdfPath, false, watermark);
}
if (".txt".equalsIgnoreCase(suffix) || ".html".equalsIgnoreCase(suffix) || ".properties".equalsIgnoreCase(suffix) || ".config".equalsIgnoreCase(suffix)) {
OfficeUtil.textToPdfWithWater(filePath, pdfPath, false, watermark);
}
if ("image".equalsIgnoreCase(attachment.getRelationMark())) {
OfficeUtil.imgToPdfWithWater(filePath, pdfPath, false, watermark);
} else {
if (".jpg".equalsIgnoreCase(suffix) || ".png".equalsIgnoreCase(suffix) || ".jpeg".equalsIgnoreCase(suffix)) {
OfficeUtil.imgToPdfWithWater(filePath, pdfPath, false, watermark);
}
}
}
String pdfFile = attachment.getRequestUrl() + id + ".pdf";
return new ResponseData(pdfFile);
} catch (Exception ex) {
ex.printStackTrace();
}
return new ResponseData("-1", "获取文件路径失败!", null);
}
}
各种文件生成pdf文件
需积分: 5 162 浏览量
2023-07-17
17:33:33
上传
评论
收藏 99.1MB ZIP 举报
增肥的程序员
- 粉丝: 0
- 资源: 6
最新资源
- 使用ASP.NET Core和Entity Framework Core来构建一个基本的进销存系统.rar
- 深度学习经典数据集+FER2013面部表情识别+附带使用方法的python代码
- Python中,要实现连接多个相机并识别多个二维码.rar
- 使用FFT算法对一个信号进行分析.rar
- 171cms游戏应用下载系统源码.zip
- 基于jsp+servlet+mysql蛋糕甜品店购物网站源码+数据库(期末大作业).zip
- Java项目:在线蛋糕商城系统(java+jsp+mysql)源码+数据库+期末大作业.zip
- ZapyaClient10_7-1.apk
- 织梦cms站长导航网站源码.zip
- 基于SSM+MySQL的网络投票调查问卷系统源码+数据库(java期末大作业).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈