Commit 05f76520 authored by 徐俊's avatar 徐俊
parents a95a349f 456d64f9
...@@ -15,7 +15,6 @@ import com.yiboshi.science.service.ComFileService; ...@@ -15,7 +15,6 @@ import com.yiboshi.science.service.ComFileService;
import com.yiboshi.science.service.ComProjectService; import com.yiboshi.science.service.ComProjectService;
import com.yiboshi.science.service.ComProjectTaskService; import com.yiboshi.science.service.ComProjectTaskService;
import com.yiboshi.science.service.SystemParameterService; import com.yiboshi.science.service.SystemParameterService;
import com.yiboshi.science.utils.PdfUtil;
import com.yiboshi.science.utils.ProjectInfoToPDF; import com.yiboshi.science.utils.ProjectInfoToPDF;
import com.yiboshi.science.utils.StringUtil; import com.yiboshi.science.utils.StringUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -87,25 +86,6 @@ public class ComProjectController extends BaseController<ComProjectService, ComP ...@@ -87,25 +86,6 @@ public class ComProjectController extends BaseController<ComProjectService, ComP
return ResponseDataModel.ok(comProjectService.getCount(e)); return ResponseDataModel.ok(comProjectService.getCount(e));
} }
@ApiOperation(value = "项目信息导出", httpMethod = "POST", notes = "项目信息导出")
@RequestMapping("/export1/{id}")
@PostMapping
public void export1(@PathVariable String id) {
comProjectService.export(id, request, response);
}
@ApiOperation(value = "项目信息导出", httpMethod = "POST", notes = "项目信息导出")
@RequestMapping("/export/{id}")
@PostMapping
public ResponseDataModel<byte[]> export(@PathVariable String id) {
try {
return ResponseDataModel.ok(PdfUtil.createPDF(response, "tmp-report.html", new ComProject()));
} catch (Exception e) {
return new ResponseDataModel(ResponseCode.SERVER_ERROR, "");
}
}
/** /**
* 根据id获取项目信息 * 根据id获取项目信息
* *
......
...@@ -21,13 +21,11 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -21,13 +21,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 功能:任务书表 接口 * 功能:任务书表 接口
...@@ -157,7 +155,8 @@ public class ComProjectTaskController extends BaseController<ComProjectTaskServi ...@@ -157,7 +155,8 @@ public class ComProjectTaskController extends BaseController<ComProjectTaskServi
// 生成PDF文件字节数组 // 生成PDF文件字节数组
// byte[] pdfBytes = TaskInfoToPDFUtil.createContractPdf(dto); // byte[] pdfBytes = TaskInfoToPDFUtil.createContractPdf(dto);
byte[] pdfBytes = TaskToPDF.createContractPdf(dto); // byte[] pdfBytes = TaskToPDF.createContractPdf(dto);
byte[] pdfBytes = TalentToPDF.createContractPdf(dto);
// 设置响应头 // 设置响应头
response.setContentType("application/pdf"); response.setContentType("application/pdf");
String fileName = new String((dto.getProjName() + ".pdf").getBytes("UTF-8"), "ISO-8859-1"); String fileName = new String((dto.getProjName() + ".pdf").getBytes("UTF-8"), "ISO-8859-1");
......
...@@ -253,7 +253,7 @@ public class ComProjectAssignServiceImpl extends BaseServiceImpl<ComProjectAssig ...@@ -253,7 +253,7 @@ public class ComProjectAssignServiceImpl extends BaseServiceImpl<ComProjectAssig
economyScore = new BigDecimal(df1.format(economyScore)); economyScore = new BigDecimal(df1.format(economyScore));
} }
totalScore = technologyScore.add(economyScore); totalScore = technologyScore.add(economyScore);
calculateScore = technologyAverageScore.multiply(new BigDecimal(0.8)).add(economyAverageScore.multiply(new BigDecimal(0.2))); calculateScore = technologyAverageScore.multiply(new BigDecimal(1)).add(economyAverageScore.multiply(new BigDecimal(1)));
calculateScore = new BigDecimal(df1.format(calculateScore)); calculateScore = new BigDecimal(df1.format(calculateScore));
if (list.size() > personCount) if (list.size() > personCount)
completed = 0; completed = 0;
......
...@@ -17,7 +17,6 @@ import com.yiboshi.science.entity.ComProjectConclusion; ...@@ -17,7 +17,6 @@ import com.yiboshi.science.entity.ComProjectConclusion;
import com.yiboshi.science.param.query.ComProjectConclusionQueryVO; import com.yiboshi.science.param.query.ComProjectConclusionQueryVO;
import com.yiboshi.science.service.*; import com.yiboshi.science.service.*;
import com.yiboshi.science.utils.DateUtils; import com.yiboshi.science.utils.DateUtils;
import com.yiboshi.science.utils.PdfUtil;
import org.apache.velocity.VelocityContext; import org.apache.velocity.VelocityContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -339,7 +338,7 @@ public class ComProjectConclusionServiceImpl extends BaseServiceImpl<ComProjectC ...@@ -339,7 +338,7 @@ public class ComProjectConclusionServiceImpl extends BaseServiceImpl<ComProjectC
context.put("day", day >= 10 ? day : "0" + day); context.put("day", day >= 10 ? day : "0" + day);
try (ServletOutputStream outputStream = response.getOutputStream()) { try (ServletOutputStream outputStream = response.getOutputStream()) {
PdfUtil.pdfFile(context, "/template/demo.html", outputStream);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -963,23 +963,7 @@ public class ComProjectServiceImpl extends BaseServiceImpl<ComProjectDAO, ComPro ...@@ -963,23 +963,7 @@ public class ComProjectServiceImpl extends BaseServiceImpl<ComProjectDAO, ComPro
public void export(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) { public void export(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) {
String filename = System.currentTimeMillis() + ".pdf";
response.reset();
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "inline; filename=" + URLUtil.encode(filename, CharsetUtil.CHARSET_UTF_8));
VelocityContext context = new VelocityContext();
Calendar calendar = Calendar.getInstance();
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DATE);
context.put("reportYear", 2024);
context.put("year", calendar.get(Calendar.YEAR));
context.put("month", month >= 10 ? month : "0" + month);
context.put("day", day >= 10 ? day : "0" + day);
try (ServletOutputStream outputStream = response.getOutputStream()) {
PdfUtil.pdfFile(context, "/template/tmp-report.html", outputStream);
} catch (Exception e) {
e.printStackTrace();
}
} }
......
package com.yiboshi.science.utils; package com.yiboshi.science.utils;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter; import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.font.PdfFont; import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory; import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.PageSize; import com.itextpdf.layout.Document;
import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.layout.borders.Border;
import com.itextpdf.kernel.pdf.PdfWriter; import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.font.FontProvider; import com.itextpdf.layout.element.Cell;
import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.layout.element.Paragraph;
import com.lowagie.text.DocumentException; import com.itextpdf.layout.element.Table;
import freemarker.cache.ClassTemplateLoader; import com.itextpdf.layout.properties.HorizontalAlignment;
import freemarker.template.Configuration; import com.itextpdf.layout.properties.TextAlignment;
import freemarker.template.TemplateException; import com.itextpdf.layout.properties.VerticalAlignment;
import freemarker.template.TemplateExceptionHandler; import com.itextpdf.text.DocumentException;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.xhtmlrenderer.pdf.ITextRenderer;
import javax.servlet.http.HttpServletResponse; import java.text.SimpleDateFormat;
import java.io.IOException; import java.util.Objects;
import java.io.OutputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import static java.lang.System.in; import static com.yiboshi.science.utils.ProjectInfoToPDF.getCurrentOperatingSystem;
/** /**
* PDF工具 * PDF工具
...@@ -38,94 +29,95 @@ import static java.lang.System.in; ...@@ -38,94 +29,95 @@ import static java.lang.System.in;
*/ */
public class PdfUtil { public class PdfUtil {
static { static float borderWidth = 1f;
// Velocity初始化 static Border unitedBorder = new SolidBorder(new DeviceRgb(0, 0, 0), borderWidth);
Velocity.setProperty(RuntimeConstants.OUTPUT_ENCODING, StandardCharsets.UTF_8);
Velocity.setProperty(RuntimeConstants.INPUT_ENCODING, StandardCharsets.UTF_8);
Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
Velocity.init();
}
/** private static PdfFont createFont(String fontName) {
* 据模板生成pfd格式文件 try {
* if ("linux".equals(getCurrentOperatingSystem())) {
* @param context 上下文对象 if (fontName.toLowerCase().endsWith(".ttc"))
* @param template pdf模板 return PdfFontFactory.createFont("/usr/share/fonts/" + fontName + ",0", PdfEncodings.IDENTITY_H);
* @param outputStream 生成ofd文件输出流 else
*/ return PdfFontFactory.createFont("/usr/share/fonts/" + fontName, PdfEncodings.IDENTITY_H);
public static void pdfFile(Context context, String template, OutputStream outputStream) { } else {
try (PdfWriter pdfWriter = new PdfWriter(outputStream)) { if (fontName.toLowerCase().endsWith(".ttc"))
PdfDocument pdfDocument = new PdfDocument(pdfWriter); return PdfFontFactory.createFont("c:/Windows/Fonts/" + fontName + ",0", PdfEncodings.IDENTITY_H);
pdfDocument.setDefaultPageSize(PageSize.A4); else
ConverterProperties properties = new ConverterProperties(); return PdfFontFactory.createFont("c:/Windows/Fonts/" + fontName, PdfEncodings.IDENTITY_H);
FontProvider fontProvider = new FontProvider(); }
} catch (Exception e) {
throw new RuntimeException("加载字体文件失败,请确保系统中存在字体文件 " + fontName + ":" + e.getMessage(), e);
}
}
public static void addTablePageCell(Table table, String label, String value, Integer labelColspan, Integer valueColspan, PdfFont font) {
if (Objects.isNull(labelColspan))
labelColspan = 1;
if (Objects.isNull(valueColspan))
valueColspan = 1;
Cell labelCell = new Cell(1, labelColspan);
labelCell.setMinHeight(36f);
labelCell.setVerticalAlignment(VerticalAlignment.BOTTOM);
labelCell.setHorizontalAlignment(HorizontalAlignment.LEFT);
labelCell.setBorder(new SolidBorder(new DeviceRgb(0, 0, 0), 0.1f)); // 设置边框宽度
labelCell.add(new Paragraph(label != null ? label.toString() : "").setFont(font).setFontSize(15));
labelCell.setBorder(Border.NO_BORDER);
table.addCell(labelCell);
// 字体设置,解决中文不显示问题 Cell valueCell = new Cell(1, valueColspan);
PdfFont sysFont = PdfFontFactory.createFont("STSongStd-Light", "UniGB-UCS2-H"); valueCell.setPadding(3f);
fontProvider.addFont(sysFont.getFontProgram(), "UniGB-UCS2-H"); valueCell.setMinHeight(36f);
properties.setFontProvider(fontProvider); valueCell.setVerticalAlignment(VerticalAlignment.BOTTOM);
valueCell.setHorizontalAlignment(HorizontalAlignment.LEFT);
// 只设置下边框
valueCell.setBorderTop(Border.NO_BORDER);
valueCell.setBorderLeft(Border.NO_BORDER);
valueCell.setBorderRight(Border.NO_BORDER);
valueCell.setBorderBottom(unitedBorder);
valueCell.add(new Paragraph(value != null ? value.toString() : "").setFont(font).setFontSize(15));
table.addCell(valueCell);
}
Template pfdTemplate = Velocity.getTemplate(template, "UTF-8"); public static void addValueCell(Table table, String label, Integer labelColspan, String value, Integer valueColspan, Float height, PdfFont font, Float fontSize, VerticalAlignment vertical, HorizontalAlignment horizontal) {
StringWriter writer = new StringWriter(); addCell(table, label, labelColspan, null, height, font, fontSize, vertical, horizontal);
pfdTemplate.merge(context, writer); addCell(table, value, valueColspan, null, height, font, fontSize, vertical, horizontal);
}
HtmlConverter.convertToPdf(writer.toString(), pdfDocument, properties); public static void addCell(Table table, Object value, Integer colspan, Integer rowspan, Float height, PdfFont font, Float fontSize, VerticalAlignment vertical, HorizontalAlignment horizontal) {
if (Objects.isNull(font))
font = createFont("simsun.ttc");
if (Objects.isNull(fontSize))
fontSize = 10.5f;
if (Objects.isNull(height))
height = 25.5f;
if (Objects.isNull(colspan))
colspan = 1;
if (Objects.isNull(rowspan))
rowspan = 1;
if (Objects.isNull(vertical))
vertical = VerticalAlignment.MIDDLE;
if (Objects.isNull(horizontal))
horizontal = HorizontalAlignment.CENTER;
Cell cell = new Cell(rowspan, colspan);
cell.setPadding(5f);
cell.setMinHeight(height);
cell.setVerticalAlignment(vertical);
cell.setHorizontalAlignment(horizontal);
pdfDocument.close(); cell.setBorderRight(unitedBorder);
} catch (Exception e) { cell.setBorderBottom(unitedBorder);
throw new RuntimeException("PFD文件生成失败", e); // 创建段落并检查字体
} cell.add(new Paragraph(value != null ? value.toString() : "").setFont(font).setFontSize(fontSize));
table.addCell(cell);
} }
public static void setParagraph(Document document, Object value, PdfFont font, float FontSize, boolean bold) throws DocumentException {
public static byte[] createPDF(HttpServletResponse response, String temp, Object dataModel) throws IOException, TemplateException, DocumentException { Paragraph paragraph = new Paragraph(value != null ? value.toString() : "")
Map<String, Object> dataMap = HtmlBuilder.obj2Map(dataModel); .setFont(font)
// 配置FreeMarker .setFontSize(FontSize)
Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); .setTextAlignment(TextAlignment.LEFT) // 设置文字对齐方式
cfg.setDefaultEncoding("utf-8"); .setMarginLeft(1f); // 设置左缩进
cfg.setClassLoaderForTemplateLoading(PdfUtil.class.getClassLoader(), "template"); if (bold) {
cfg.setTemplateLoader(new ClassTemplateLoader(PdfUtil.class.getClassLoader(), "/template")); paragraph.setBold();
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// 获取模板
freemarker.template.Template template = cfg.getTemplate(temp, "utf-8");
// 处理模板,生成HTML内容
StringWriter tmpText = new StringWriter();
template.process(dataMap, tmpText);
String htmlContent = tmpText.toString();
// 创建PDF渲染器
ITextRenderer renderer = new ITextRenderer();
// Java代码示例
// renderer.getSharedContext().setDPI(1); // 提高DPI减少锯齿
// 设置中文字体
String simPath = ResourceFileUtil.getAbsolutePath("/fonts/simsun.ttc");
String msyhPath = ResourceFileUtil.getAbsolutePath("/fonts/msyh.ttc");
renderer.getFontResolver().addFont(simPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.getFontResolver().addFont(msyhPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
// 渲染HTML内容
renderer.setDocumentFromString(htmlContent);
renderer.layout();
// 创建一个ByteArrayOutputStream来保存生成的PDF
response.setContentType("application/octet-stream;charset=UTF-8");
OutputStream outputStream = response.getOutputStream();
// 输出PDF到字节数组
renderer.createPDF(outputStream);
//创建存放文件内容的数组
byte[] buff = new byte[1024];
//所读取的内容使用n来接收
int n;
//当没有读取完时,继续读取,循环
while ((n = in.read(buff)) != -1) {
//将字节数组的数据全部写入到输出流中
outputStream.write(buff, 0, n);
} }
//强制将缓存区的数据进行输出 document.add(paragraph);
outputStream.flush();
//关流
outputStream.close();
in.close();
// 关闭输出流
return buff;
} }
} }
package com.yiboshi.science.utils;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.element.AreaBreak;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.properties.*;
import com.itextpdf.text.DocumentException;
import com.yiboshi.science.param.dto.ComProjectCooperativeUnitsDTO;
import com.yiboshi.science.param.dto.ComProjectTaskDTO;
import java.io.ByteArrayOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static com.yiboshi.science.utils.PdfUtil.*;
import static com.yiboshi.science.utils.PdfUtil.addCell;
import static com.yiboshi.science.utils.ProjectInfoToPDF.getCurrentOperatingSystem;
public class TalentToPDF {
static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
static SimpleDateFormat sdfM = new SimpleDateFormat("yyyy年MM月");
static float borderWidth = 1f;
static Border unitedBorder = new SolidBorder(new DeviceRgb(0, 0, 0), borderWidth);
private static PdfFont createFont(String fontName) {
try {
if ("linux".equals(getCurrentOperatingSystem())) {
if (fontName.toLowerCase().endsWith(".ttc"))
return PdfFontFactory.createFont("/usr/share/fonts/" + fontName + ",0", PdfEncodings.IDENTITY_H);
else
return PdfFontFactory.createFont("/usr/share/fonts/" + fontName, PdfEncodings.IDENTITY_H);
} else {
if (fontName.toLowerCase().endsWith(".ttc"))
return PdfFontFactory.createFont("c:/Windows/Fonts/" + fontName + ",0", PdfEncodings.IDENTITY_H);
else
return PdfFontFactory.createFont("c:/Windows/Fonts/" + fontName, PdfEncodings.IDENTITY_H);
}
} catch (Exception e) {
throw new RuntimeException("加载字体文件失败,请确保系统中存在字体文件 " + fontName + ":" + e.getMessage(), e);
}
}
/**
* 生成项目合同书PDF
*
* @param dto 项目任务信息
* @return PDF文件字节数组
*/
public static byte[] createContractPdf(ComProjectTaskDTO dto) throws DocumentException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(baos));
Document document = new Document(pdfDoc);
try {
// 设置页边距 (左, 右, 上, 下)
document.setMargins(72f, 54f, 72f, 54f);
// 宋体
PdfFont sfChinese = createFont("simsun.ttc");
// 仿宋
PdfFont fsChinese = createFont("simfang.ttf");
// 首页
firstPageInfo(document, dto, sfChinese, fsChinese);
// 填表说明
tableDescription(document, dto, sfChinese, fsChinese);
// 申报人基本情况
basicInformation(document, dto, sfChinese, fsChinese);
// 申报人学习、研修与工作简历
basicInformation1(document, dto, sfChinese, fsChinese);
// 关闭文档
document.close();
return baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static void firstPageInfo(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 附件编号
Paragraph paragraph = new Paragraph("附件3").setFont(bfChinese).setFontSize(16).setBold();
paragraph.setTextAlignment(TextAlignment.LEFT);
document.add(paragraph);
document.add(new Paragraph("\n\n"));
// 添加标题
Paragraph title = new Paragraph("云南省医学高端人才申报表").setFont(bfChinese).setFontSize(22);
title.setTextAlignment(TextAlignment.CENTER);
document.add(title);
document.add(new Paragraph("\n\n\n\n\n\n"));
float[] columnWidths = {65f, 15f, 200f};
Table table = new Table(columnWidths);
// 设置表格水平居中
table.setHorizontalAlignment(HorizontalAlignment.CENTER);
table.setWidth(UnitValue.createPointValue(400f));
// table.setBorder(unitedBorder);
// 添加表格内容
addTablePageCell(table, "申报人姓名:", dto.getProjName(), 2, null, bfChinese);
addTablePageCell(table, "从事专业:", dto.getAppUnitName(), null, 2, bfChinese);
addTablePageCell(table, "单位名称:", dto.getAppUnitName(), null, 2, bfChinese);
addTablePageCell(table, "单位公章:", dto.getAppPersonName(), null, 2, bfChinese);
document.add(table);
}
private static void tableDescription(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加标题
Paragraph title = new Paragraph("填 表 说 明").setFont(bfChinese).setFontSize(16);
title.setTextAlignment(TextAlignment.CENTER);
document.add(title);
document.add(new Paragraph("\n"));
// 添加填表说明内容
List<String> descriptions = new ArrayList<>();
descriptions.add("一、填写本表前请认真阅读《云南省卫生健康委 云南省财政厅关于印发云南省高层次卫生健康技术人才培养等 4 个项目实施方案的通知》(云卫科教发〔2024〕1号)的《云南省高层次卫生健康技术人才培养项目实施办法(试行)》。");
descriptions.add("二、申报表内各项内容应实事求是,认真填写。");
descriptions.add("三、单位名称必须与单位公章上的名称相一致,不能用简称。");
descriptions.add("四、省级或省级以上人才指“国家杰出青年基金“获得者,“国务院政府特殊津贴“获得者,国家卫生健康委“有突出贡献的中青年专家“获得者,教育部“长江学者“获得者,人力资源和社会保障部“百千万“人才工程获得者,云南省中青年学术和技术带头人获得者,省科技领军人才,省创新团队带头人,省科技创新人才获得者。");
descriptions.add("五、表格四中“申报人特研学术成绩“填报时限为2019年1月1日至2024年1月1日。");
descriptions.add("六、申报表用A4纸打印,并在左侧装订成册,一式十份,每份均须加盖单位公章。");
descriptions.add("七、所附材料包括学位证书、荣誉证书、获奖证书复印件、社会团体聘书复印件、论文、专著和教材的封面、目录、版权页复印件。在加上封面和材料目录后按此次序在左侧装订成册,一式一份。");
// 添加填表说明内容
for (String desc : descriptions) {
Paragraph p = new Paragraph(desc).setFont(fsChinese).setFontSize(12);
p.setFirstLineIndent(24f); // 设置首行缩进
p.setMultipliedLeading(1.5f); // 设置行间距
document.add(p);
}
}
private static void basicInformation(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
// 创建表格
float[] column = {10f, 20f, 10f, 10f, 10f, 10f, 10f, 20f, 6.5f, 6.5f, 6.5f, 20f};
Table table = new Table(column);
table.setWidth(UnitValue.createPercentValue(100));
table.setBorder(unitedBorder);
addCell(table, "个人\n" + "情况\n", null, 11, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 基本信息行
addValueCell(table, "姓名", 1, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "性别", 2, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "民族", 3, "", 1, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 出生年月等信息行
addValueCell(table, "出生年月", 1, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "最高学位", 2, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "最高学位\n授予时间", 3, "", 1, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 最高学位等信息行
addValueCell(table, "最高学位\n授予单位", 1, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "目前从事\n专业", 2, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addCell(table, "是否为研究\n生导师", 3, null, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addCell(table, "博导□\n硕导□\n否□", 1, null, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 专业技术职称等信息行
addValueCell(table, "专业技术\n职称", 1, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "职派", 2, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "行政职务", 3, "", 1, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 是否是省级人才
String talentText = "国家杰出青年基金□,国务院政府特殊津贴□,国家卫健委有突出贡献的中青年专家□,教育部长江学者□,人力资源和社会保障部“百千万”人才工程□,云南省中青年学术和技术带头人□,省科技领军人才□,省创新团队带头人□,省科技创新人才获得者□。";
addValueCell(table, "是否是省级或\n以上人才", 1, talentText, 10, 50f, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
// 个人情况相关行
addValueCell(table, "省级及以上专\n家称号、先进\n工作者等荣誉\n称号", 1, "", 10, 50f, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "在国家、省级\n学术团体中任\n职情况(包括\n任职时间和职\n务)", 1, "", 10, 50f, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "担任国内统计\n源期刊编委情\n况(包括任职\n时间和职务)", 1, "", 10, 50f, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "担任国家或省\n级重点学科/\n专科、重点实\n验室、内设研\n究机构负责人\n情况(包括任\n职时间和职\n务)", 1, "", 10, 50f, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 联系方式行
addCell(table, "联系方式", 1, 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
addValueCell(table, "电话", 1, "", 4, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "传真:", 1, "", 4, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "Email:", 1, "", 9, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.RIGHT);
// 申报单位信息
addCell(table, "所在\n单位\n情况", 1, 4, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 单位名称
addValueCell(table, "单位名称", 1, "", 10, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
// 支撑条件
String supportText = "1.所在学科的优势(包括综合实力、学术水平);2.学术梯队;3.理实条件;4. :";
addValueCell(table, "支撑条件:", 1, supportText, 10, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
// 主管部门等信息行
addValueCell(table, "主管部门", 1, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "电话", 1, "", 3, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addValueCell(table, "邮编", 1, "", 3, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
// 通讯地址
addValueCell(table, "通讯地址", 1, "", 10, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
addCell(table, "自评\n研究\n内容", 1, 4, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 研究方向
addValueCell(table, "研究方向", 1, "", 10, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
// 研究类别
addValueCell(table, "研究类别:", 1, "A.基础研究□ B.应用研究□ C.开发研究□", 10, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
// 研究基础与进展
addValueCell(table, "研究起止年月", 1, "", 2, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
// 研究基础与进展
addValueCell(table, "研究基础与进展:\n研究基础(包括已取得的主要研究成果):", 4, "", 4, null, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.LEFT);
// 研究目的等
addCell(table, "研究目的、意义、关键技术的主要内容及预期效果(限100字)", 11, 1, 80f, bfChinese, null, VerticalAlignment.MIDDLE, HorizontalAlignment.CENTER);
// 添加表格到文档
document.add(table);
}
private static void basicInformation1(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation2(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation3(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation4(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation5(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation6(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation7(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation8(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation9(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
private static void basicInformation10(Document document, ComProjectTaskDTO dto, PdfFont bfChinese, PdfFont fsChinese) throws DocumentException {
// 添加新页面
document.add(new AreaBreak());
// 添加段落标题
setParagraph(document, "申报人基本情况", bfChinese, 12f, true);
}
}
...@@ -25,6 +25,7 @@ import java.util.ArrayList; ...@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import static com.yiboshi.science.utils.PdfUtil.*;
import static com.yiboshi.science.utils.ProjectInfoToPDF.getCurrentOperatingSystem; import static com.yiboshi.science.utils.ProjectInfoToPDF.getCurrentOperatingSystem;
public class TaskToPDF { public class TaskToPDF {
...@@ -259,88 +260,4 @@ public class TaskToPDF { ...@@ -259,88 +260,4 @@ public class TaskToPDF {
} }
document.add(projTable); document.add(projTable);
} }
private static void addTablePageCell(Table table, String label, String value, Integer labelColspan, Integer valueColspan, PdfFont font) {
if (Objects.isNull(labelColspan))
labelColspan = 1;
if (Objects.isNull(valueColspan))
valueColspan = 1;
Cell labelCell = new Cell(1, labelColspan);
labelCell.setMinHeight(36f);
labelCell.setVerticalAlignment(VerticalAlignment.BOTTOM);
labelCell.setHorizontalAlignment(HorizontalAlignment.LEFT);
labelCell.setBorder(new SolidBorder(new DeviceRgb(0, 0, 0), 0.1f)); // 设置边框宽度
labelCell.add(new Paragraph(label != null ? label.toString() : "").setFont(font).setFontSize(15));
labelCell.setBorder(Border.NO_BORDER);
table.addCell(labelCell);
Cell valueCell = new Cell(1, valueColspan);
valueCell.setPadding(3f);
valueCell.setMinHeight(36f);
valueCell.setVerticalAlignment(VerticalAlignment.BOTTOM);
valueCell.setHorizontalAlignment(HorizontalAlignment.LEFT);
// 只设置下边框
valueCell.setBorderTop(Border.NO_BORDER);
valueCell.setBorderLeft(Border.NO_BORDER);
valueCell.setBorderRight(Border.NO_BORDER);
valueCell.setBorderBottom(unitedBorder);
valueCell.add(new Paragraph(value != null ? value.toString() : "").setFont(font).setFontSize(15));
table.addCell(valueCell);
}
private static void addValueCell(Table table, String label, Integer labelColspan, String value, Integer valueColspan, Float height, PdfFont font, Float fontSize, VerticalAlignment vertical, HorizontalAlignment horizontal) {
addCell(table, label, labelColspan, null, height, font, fontSize, vertical, horizontal);
addCell(table, value, valueColspan, null, height, font, fontSize, vertical, horizontal);
}
private static void addCell(Table table, Object value, Integer colspan, Integer rowspan, Float height, PdfFont font, Float fontSize, VerticalAlignment vertical, HorizontalAlignment horizontal) {
if (Objects.isNull(font))
font = createFont("simsun.ttc");
if (Objects.isNull(fontSize))
fontSize = 10.5f;
if (Objects.isNull(height))
height = 25.5f;
if (Objects.isNull(colspan))
colspan = 1;
if (Objects.isNull(rowspan))
rowspan = 1;
if (Objects.isNull(vertical))
vertical = VerticalAlignment.MIDDLE;
if (Objects.isNull(horizontal))
horizontal = HorizontalAlignment.CENTER;
Cell cell = new Cell(rowspan, colspan);
cell.setPadding(5f);
cell.setMinHeight(height);
cell.setVerticalAlignment(vertical);
cell.setHorizontalAlignment(horizontal);
cell.setBorderRight(unitedBorder);
cell.setBorderBottom(unitedBorder);
// 创建段落并检查字体
cell.add(new Paragraph(value != null ? value.toString() : "").setFont(font).setFontSize(fontSize));
table.addCell(cell);
}
// 为了保持兼容性,添加原有方法的重载
private static void setParagraph(Document document, Object value, PdfFont font, float FontSize, boolean bold) throws DocumentException {
Paragraph paragraph = new Paragraph(value != null ? value.toString() : "")
.setFont(font)
.setFontSize(FontSize)
.setTextAlignment(TextAlignment.LEFT) // 设置文字对齐方式
.setMarginLeft(1f); // 设置左缩进
if (bold) {
paragraph.setBold();
}
document.add(paragraph);
}
private static String numberTo(int number) {
char[] cs = "零一二三四五六七八九".toCharArray();
String temp = "";
while (number > 0) {
temp += cs[number % 10];
number /= 10;
}
return temp;
}
} }
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