diff --git a/src/main/java/cn/teammodel/controller/frontend/HelloController.java b/src/main/java/cn/teammodel/controller/frontend/HelloController.java index a237804..caeb1a3 100644 --- a/src/main/java/cn/teammodel/controller/frontend/HelloController.java +++ b/src/main/java/cn/teammodel/controller/frontend/HelloController.java @@ -3,16 +3,8 @@ package cn.teammodel.controller.frontend; import cn.teammodel.common.R; import cn.teammodel.repository.AppraiseRepository; import cn.teammodel.service.EvaluationService; -import cn.teammodel.utils.ChartUtil; -import cn.teammodel.utils.PdfUtil; import com.itextpdf.text.DocumentException; -import com.itextpdf.text.pdf.PdfReader; -import com.itextpdf.text.pdf.PdfStamper; import io.swagger.annotations.Api; -import org.jfree.chart.ChartUtils; -import org.jfree.chart.JFreeChart; -import org.jfree.data.general.DefaultPieDataset; -import org.springframework.core.io.ClassPathResource; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.GetMapping; @@ -20,12 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.util.Map; @RestController @RequestMapping("/") @@ -51,37 +39,37 @@ public class HelloController { } @GetMapping("public/pdf") - public void freepdf(HttpServletResponse response) throws DocumentException, IOException { - // 设置response参数 - response.reset(); - response.setContentType("application/pdf"); - response.setHeader("Content-disposition", - "attachment;filename=report_student_" + System.currentTimeMillis() + ".pdf"); - ClassPathResource resource = new ClassPathResource("templates/pdf_templates/student_report.pdf"); - InputStream in = resource.getInputStream(); - ServletOutputStream os = response.getOutputStream(); - // 处理 stampter - PdfReader pdfReader = new PdfReader(in); - PdfStamper stamper = new PdfStamper(pdfReader, os); - - Map data = PdfUtil.data(); - DefaultPieDataset dataset = new DefaultPieDataset( ); - dataset.setValue( "IPhone 5s" , new Double( 20 ) ); - dataset.setValue( "SamSung Grand" , new Double( 20 ) ); - dataset.setValue( "MotoG" , new Double( 40 ) ); - dataset.setValue( "Nokia Lumia" , new Double( 10 ) ); - - JFreeChart pieChart = ChartUtil.pieChart("手机销量统计", dataset); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ChartUtils.writeChartAsJPEG(bos, pieChart, 850, 440); - // 填充表单 - PdfUtil.fillPdfForm(stamper, data); - PdfUtil.fillImage(stamper, "praiseDistribution", bos.toByteArray()); - PdfUtil.fillImage(stamper, "criticalDistribution", bos.toByteArray()); - // 关闭流 - stamper.setFormFlattening(true); - stamper.close(); - os.close(); + public void freepdf(HttpServletResponse response) throws DocumentException, IOException { // 设置response参数 +// response.reset(); +// response.setContentType("application/pdf"); +// response.setHeader("Content-disposition", +// "attachment;filename=report_student_" + System.currentTimeMillis() + ".pdf"); +// ClassPathResource resource = new ClassPathResource("templates/pdf_templates/student_report.pdf"); +// InputStream in = resource.getInputStream(); +// ServletOutputStream os = response.getOutputStream(); +// // 处理 stampter +// PdfReader pdfReader = new PdfReader(in); +// PdfStamper stamper = new PdfStamper(pdfReader, os); +// +// Map data = PdfUtil.data(); +// DefaultPieDataset dataset = new DefaultPieDataset( ); +// dataset.setValue( "IPhone 5s" , new Double( 20 ) ); +// dataset.setValue( "SamSung Grand" , new Double( 20 ) ); +// dataset.setValue( "MotoG" , new Double( 40 ) ); +// dataset.setValue( "Nokia Lumia" , new Double( 10 ) ); +// +// JFreeChart pieChart = ChartUtil.pieChart("手机销量统计", dataset); +// ByteArrayOutputStream bos = new ByteArrayOutputStream(); +// ChartUtils.writeChartAsJPEG(bos, pieChart, 850, 440); +// // 填充表单 +// PdfUtil.fillPdfForm(stamper, data); +// PdfUtil.fillImage(stamper, "praiseDistribution", bos.toByteArray()); +// PdfUtil.fillImage(stamper, "criticalDistribution", bos.toByteArray()); +// // 关闭流 +// stamper.setFormFlattening(true); +// stamper.close(); +// os.close(); +// } diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index 5824ff9..6c2e46a 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -668,7 +668,7 @@ public class EvaluationServiceImpl implements EvaluationService { PdfUtil.fillImage(stamper, "praiseDistribution", praiseBos.toByteArray()); PdfUtil.fillImage(stamper, "criticalDistribution", criticalBos.toByteArray()); // 关闭流 - stamper.setFormFlattening(true); +// stamper.setFormFlattening(true); stamper.close(); os.close(); diff --git a/src/main/resources/templates/pdf_templates/student_report.pdf b/src/main/resources/templates/pdf_templates/student_report.pdf index 6191a2b..4b286ac 100644 Binary files a/src/main/resources/templates/pdf_templates/student_report.pdf and b/src/main/resources/templates/pdf_templates/student_report.pdf differ