Commit 401dd323 authored by 徐俊's avatar 徐俊

xujun

parent ef24d374
......@@ -214,15 +214,31 @@ public class ComProjectController extends BaseController<ComProjectService, ComP
return ResponseDataModel.ok(comProjectService.projectImport(list));
}
@ApiOperation(value = "项目信息导出1", httpMethod = "POST", notes = "项目信息导出1")
@ApiOperation(value = "项目信息导出", httpMethod = "POST", notes = "项目信息导出")
@RequestMapping("/projectExport/{id}")
@PostMapping
public ResponseDataModel<String> projectExport(@PathVariable String id) throws DocumentException, IOException {
public void projectExport(@PathVariable String id) throws DocumentException, IOException {
try {
List<SystemParameter> list = systemParameterService.getListByType(67);
ComProjectDTO dto = comProjectService.getProjectById(id);
String outputPath = "D:\\申请书和合同书.pdf";
ProjectInfoToPDF.generateProjectPDF(dto, outputPath, list);
return ResponseDataModel.ok("项目信息导入成功!");
// 生成PDF文件字节数组
byte[] pdfBytes = ProjectInfoToPDF.generateProjectPDF(dto, list);
// 设置响应头
response.setContentType("application/pdf");
String fileName = new String((dto.getProjName() + ".pdf").getBytes("UTF-8"), "ISO-8859-1");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setContentLength(pdfBytes.length);
// 写入响应流
try (ServletOutputStream out = response.getOutputStream()) {
out.write(pdfBytes);
out.flush();
}
} catch (Exception e) {
response.setContentType("text/plain;charset=UTF-8");
response.getWriter().write("导出PDF失败:" + e.getMessage());
}
}
}
\ No newline at end of file
......@@ -21,11 +21,14 @@ public class ProjectInfoToPDF {
/**
* 生成项目申请书和合同书PDF
* @param project 项目信息
* @param outputPath 输出路径
* @return 生成的PDF文件字节数组
*/
public static void generateProjectPDF(ComProjectDTO project, String outputPath, List<SystemParameter> projAttributeList) throws DocumentException, IOException {
public static byte[] generateProjectPDF(ComProjectDTO project, List<SystemParameter> projAttributeList) throws DocumentException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputPath));
PdfWriter writer = PdfWriter.getInstance(document, baos);
try {
// 文件水印
String watermark = project.getAppNo();
if (project.getProjState() >= CommonEnum.projState.pass.getCode()) {
......@@ -44,8 +47,6 @@ public class ProjectInfoToPDF {
document.open();
Font normalFont = new Font(bfChinese, 12, Font.NORMAL);
Font boldFont = new Font(bfChinese, 12, Font.BOLD);
......@@ -104,6 +105,13 @@ public class ProjectInfoToPDF {
addSignatureSection(document, normalFont);
document.close();
return baos.toByteArray();
} finally {
if (document.isOpen()) {
document.close();
}
baos.close();
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment