lowagie(itext)老版本手绘PDF,包含页码、水印、图片、复选框、复杂行列合并、行高设置等。
入口类:exportPdf
package xcsy.qms.webapi.service;import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.ibm.icu.text.RuleBasedNumberFormat;
import com.lowagie.text.*;
import com.lowagie.text.Font;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.*;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.openapi.common.result.CustomApiResult;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import org.jsoup.Jsoup;
import xcsy.zjy.webapi.utils.AddImageToEachPageHeader;
import xcsy.zjy.webapi.utils.CheckBoxCellEvent;
import xcsy.zjy.webapi.utils.CheckBoxCellNotEvent;
import xcsy.zjy.webapi.utils.PdfPageUtil;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;/*** @program: xcsy-cosmic* @description: 准入报告pdf导出实现* @author: lyw* @create: 2025-02-13 09:31**/public class ReportsPDFService {private static final Log log = LogFactory.getLog(ReportsPDFService.class);// 定义全局的字体静态变量Font headFont;Font headFont2;Font contentFont;Font titleFont;Font titleFont2;Font titleFontW;SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");public CustomApiResult<String> exportPdf(HttpServletRequest request, HttpServletResponse response) throws IOException {// 单据idString id = request.getParameter("id");DynamicObject accessReportsDO = BusinessDataServiceHelper.loadSingle(id, "eo45_access_reports");// 防止日志记录获取session异常request.getSession();// 设置编码格式response.setContentType("application/pdf;charset=UTF-8");response.setCharacterEncoding("utf-8");SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");String fileName = URLEncoder.encode(accessReportsDO.getString("eo45_fac_name") + "联盟工厂质量专项评审报告" + dateFormat.format(new Date()), "UTF-8");response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".pdf");download(response, accessReportsDO);return CustomApiResult.success("成功");}private void download(HttpServletResponse response, DynamicObject reportData) {// 最大宽度try {// 不同字体(这里定义为同一种字体:包含不同字号、不同style)BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);headFont = new Font(bf, 18, Font.BOLD, new Color(0, 0, 0));headFont2 = new Font(bf, 14, Font.BOLD, new Color(0, 0, 0));titleFont = new Font(bf, 10, Font.BOLD, new Color(0, 103, 255));titleFont2 = new Font(bf, 12, Font.BOLD, new Color(0, 0, 0));titleFontW = new Font(bf, 12, Font.BOLD, new Color(251, 251, 251));contentFont = new Font(bfChinese, 10, Font.NORMAL, new Color(0, 0, 0));Document document = new Document(new RectangleReadOnly(842F, 595F));// 设置页边距document.setMargins(60, 60, 60, 30);PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());// 添加页码writer.setPageEvent(new PdfPageUtil());// 每页表头添加水印(图片)writer.setPageEvent(new AddImageToEachPageHeader());// 打开生成的pdf文件document.open();// 标题1Paragraph paragraph = new Paragraph(reportData.getString("eo45_fac_name") + "联盟工厂质量专项评审报告", headFont);paragraph.setAlignment(1);document.add(paragraph);// 评审总结DynamicObjectCollection resultsDO = reportData.getDynamicObjectCollection("eo45_report_results");DynamicObject entryResults = resultsDO.get(0);// -------基本信息buildBasicInformation(document, entryResults);// -------审核目的buildAuditAim(document, entryResults);// -------审核类型buildAuditType(document, reportData);// -------审核范围buildAuditRange(document, entryResults);// -------审核内容buildAuditContent(document, entryResults);// -------审核方法buildAuditMethod(document, entryResults);// -------审核方背景资料buildAuditData(document, entryResults);// -------审核得分buildAuditScore(document, entryResults);// -------审核结论buildAuditResult(document, entryResults);// 标题2Paragraph paragraph2 = new Paragraph("质量专项评审“否决项”评分标准", headFont2);paragraph2.setAlignment(1);document.add(paragraph2);float[] widthsOne = {10f, 20f, 60f, 10f};PdfPTable tableOne = new PdfPTable(widthsOne);handleTableOne(reportData, tableOne);document.add(tableOne);// 标题3Paragraph paragraph3 = new Paragraph("分值汇总", headFont2);paragraph3.setAlignment(1);document.add(paragraph3);float[] widthsTwo = {60f, 20f, 20f};PdfPTable tableTwo = new PdfPTable(widthsTwo);handleTableTwo(reportData, tableTwo);document.add(tableTwo);// 标题4Paragraph paragraph4 = new Paragraph("联盟工厂质量专项评审表", headFont2);paragraph4.setAlignment(1);document.add(paragraph4);float[] widthsThree = {5f, 15f, 30f, 25f, 5f, 5f, 5f, 7f, 25f};PdfPTable tableThree = new PdfPTable(widthsThree);handleTableThree(reportData, tableThree);document.add(tableThree);// 关闭文档document.close();} catch (DocumentException e) {log.error("导出pdf失败DocumentException:{}", e);} catch (Exception e) {log.error("导出pdf失败Exception:{}", e);}}private void handleTableThree(DynamicObject reportData, PdfPTable table) {// 项目分类集合DynamicObjectCollection projectCollection = reportData.getDynamicObjectCollection("eo45_report_projects");// 按eo45_project_id分组Map<String, String> projectMap = new LinkedHashMap<>();// 获取项目,以项目id作为key,排除第一项否决项,按项目seq排序projectCollection.stream().filter(e -> !"0".equals(e.getString("eo45_project_seq"))).sorted(Comparator.comparing(dynamicObject -> dynamicObject.getString("eo45_project_seq"))).forEach(e -> projectMap.put(e.getString("eo45_project_id"), e.getString("eo45_project")));// 段落在其上方留出的空间量table.setSpacingBefore(10f);// 设置表格宽度为100%// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.setHeaderRows(2);table.getDefaultCell().setHorizontalAlignment(1);// 第一行PdfPCell titleCell1 = createCenteredCellForTable("条款编号", 30, new Color(40, 120, 255), titleFontW, "border", "center");titleCell1.setRowspan(2);table.addCell(titleCell1);PdfPCell titleCell2 = createCenteredCellForTable("条款性质", 0, new Color(40, 120, 255), titleFontW, "border", "center");titleCell2.setRowspan(2);table.addCell(titleCell2);PdfPCell titleCell3 = createCenteredCellForTable("审核条款标准", 0, new Color(40, 120, 255), titleFontW, "border", "center");titleCell3.setRowspan(2);table.addCell(titleCell3);PdfPCell titleCell4 = createCenteredCellForTable("审核正面发现", 0, new Color(40, 120, 255), titleFontW, "border", "center");titleCell4.setRowspan(2);table.addCell(titleCell4);PdfPCell titleCell10 = createCenteredCellForTable("审核记录及说明", 0, new Color(40, 120, 255), titleFontW, "border", "center");titleCell10.setColspan(6);table.addCell(titleCell10);PdfPCell titleCell5 = createCenteredCellForTable("审核配分", 0, new Color(40, 120, 255), titleFontW, "border", "center");table.addCell(titleCell5);PdfPCell titleCell6 = createCenteredCellForTable("符合程度", 0, new Color(40, 120, 255), titleFontW, "border", "center");table.addCell(titleCell6);PdfPCell titleCell7 = createCenteredCellForTable("实际得分", 0, new Color(40, 120, 255), titleFontW, "border", "center");table.addCell(titleCell7);PdfPCell titleCell8 = createCenteredCellForTable("不符合类型", 0, new Color(40, 120, 255), titleFontW, "border", "center");table.addCell(titleCell8);PdfPCell titleCell9 = createCenteredCellForTable("问题描述", 0, new Color(40, 120, 255), titleFontW, "border", "center");table.addCell(titleCell9);int[] x = {0}; // 项目序号// 添加一级项目projectMap.forEach((projectId, projectName) -> {x[0]++;// 1转一RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(Locale.CHINA, RuleBasedNumberFormat.SPELLOUT);String result = formatter.format(x[0]);// 项目总分BigDecimal projectScoreAll = projectCollection.stream().filter(e -> projectId.equals(e.getString("eo45_project_id"))).map(e -> e.getBigDecimal("eo45_project_scoreall")).findFirst().orElse(BigDecimal.ZERO);PdfPCell projectCell = new PdfPCell(new Paragraph(result + "、" + projectName+ "(" + projectScoreAll.setScale(2, RoundingMode.HALF_UP) + "分)", titleFont));projectCell.setColspan(9);tableCellStyle(projectCell, new Color(237, 239, 240), new Color(242, 247, 255), "border");table.addCell(projectCell);int y = 0; // 分类序号// 二级分类for (DynamicObject categorysDynamicObject : projectCollection) {if (projectId.equals(categorysDynamicObject.getString("eo45_project_id"))) {y++;PdfPCell cellClass = new PdfPCell(new Paragraph(x[0] + "." + y + " "+ categorysDynamicObject.getString("eo45_sort_name") + "(" + categorysDynamicObject.getBigDecimal("eo45_sort_scoreall").setScale(2, RoundingMode.HALF_UP) + "分)", titleFont));cellClass.setColspan(9);tableCellStyle(cellClass, new Color(237, 239, 240), new Color(242, 247, 255), "border");table.addCell(cellClass);// 三级分类内容DynamicObjectCollection contents = categorysDynamicObject.getDynamicObjectCollection("eo45_report_contents");int z = 0; // 内容序号for (DynamicObject content : contents) {z++;String ratio = ""; // 系数// 单选题JSONArray optionArray = JSONArray.parseArray(content.getString("eo45_option_json_tag"));// 问题JSONArray problemArray = JSONArray.parseArray(content.getString("eo45_problem_json_tag"));// 合并行的数量int rowspan = 1;if (problemArray != null && !problemArray.isEmpty()) {rowspan = problemArray.size();}if (optionArray != null && !optionArray.isEmpty()) {for (int j = 0; j < optionArray.size(); j++) {JSONObject option = optionArray.getJSONObject(j);if (option.getInteger("choose") == 1) {if (!"N/A".equals(option.getString("scoreCoefficient"))&& StringUtils.isNotEmpty(option.getString("scoreCoefficient"))) {double decimal = Double.parseDouble(option.getString("scoreCoefficient"));// 转换为百分比并四舍五入到最接近的整数int percentage = (int) Math.round(decimal * 100);ratio = percentage + "%";}break;}}}PdfPCell cell1 = new PdfPCell(new Paragraph(x[0] + "." + y + "." + z, contentFont));cell1.setRowspan(rowspan);PdfPCell cell2 = setCell(3f, 1f, rowspan, content.getString("eo45_import_area"));String contentContext = "";if (StringUtils.isNotBlank(content.getString("eo45_project_context"))) {org.jsoup.nodes.Document documentResult = Jsoup.parse(content.getString("eo45_project_context"));contentContext = documentResult.text();}PdfPCell cell3 = setCell(3f, 1f, rowspan, contentContext);PdfPCell cell4 = setCell(3f, 1f, rowspan, content.getString("eo45_content_suggestion"));PdfPCell cell5 = new PdfPCell(new Paragraph(String.valueOf(content.getBigDecimal("eo45_sum_score").setScale(2, RoundingMode.HALF_UP)), contentFont));cell5.setRowspan(rowspan);PdfPCell cell6 = new PdfPCell(new Paragraph(ratio, contentFont));cell6.setRowspan(rowspan);PdfPCell cell7 = new PdfPCell(new Paragraph(String.valueOf(content.getBigDecimal("eo45_content_score").setScale(2, RoundingMode.HALF_UP)), contentFont));cell7.setRowspan(rowspan);//单元格对齐方式水平、垂直tableCellStyle(cell1, new Color(237, 239, 240), null, "border");cell1.setFixedHeight(20);tableCellStyle(cell2, new Color(237, 239, 240), null, "border");tableCellStyle(cell3, new Color(237, 239, 240), null, "border");tableCellStyle(cell4, new Color(237, 239, 240), null, "border");tableCellStyle(cell5, new Color(237, 239, 240), null, "border");tableCellStyle(cell6, new Color(237, 239, 240), null, "border");tableCellStyle(cell7, new Color(237, 239, 240), null, "border");table.addCell(cell1);table.addCell(cell2);table.addCell(cell3);table.addCell(cell4);table.addCell(cell5);table.addCell(cell6);table.addCell(cell7);PdfPCell cell8, cell9;if (problemArray != null && !problemArray.isEmpty()) {for (int j = 0; j < problemArray.size(); j++) {JSONObject problem = problemArray.getJSONObject(j);String selectContent = "";JSONArray options = JSONArray.parseArray(problem.getString("options"));for (int k = 0; k < options.size(); k++) {JSONObject option = options.getJSONObject(k);if (option.getInteger("choose") == 1) {selectContent = option.getString("selectContent");break;}}cell8 = setCell(3f, 1f, 1, selectContent);cell9 = setCell(3f, 1f, 1, problem.getString("problem_desc"));tableCellStyle(cell8, new Color(237, 239, 240), null, "border");tableCellStyle(cell9, new Color(237, 239, 240), null, "border");table.addCell(cell8);table.addCell(cell9);}} else {cell8 = new PdfPCell(new Paragraph("", contentFont));cell9 = new PdfPCell(new Paragraph("", contentFont));tableCellStyle(cell8, new Color(237, 239, 240), null, "border");tableCellStyle(cell9, new Color(237, 239, 240), null, "border");table.addCell(cell8);table.addCell(cell9);}}}}});}private void handleTableTwo(DynamicObject reportData, PdfPTable table) {// 项目分类集合DynamicObjectCollection projectCollection = reportData.getDynamicObjectCollection("eo45_report_projects");// 按eo45_project_id分组// Map<String, List<DynamicObject>> projectMap = projectCollection.stream().collect(Collectors.groupingBy(dynamicObject -> dynamicObject.getString("eo45_project_id")));Map<String, String> projectMap = new LinkedHashMap<>();// 获取项目,以项目id作为key,排除第一项否决项,按项目seq排序projectCollection.stream().filter(e -> !"0".equals(e.getString("eo45_project_seq"))).sorted(Comparator.comparing(dynamicObject -> dynamicObject.getString("eo45_project_seq"))).forEach(e -> projectMap.put(e.getString("eo45_project_id"), e.getString("eo45_project")));// 段落在其上方留出的空间量table.setSpacingBefore(10f);// 距离下方空间table.setSpacingAfter(20f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.setHeaderRows(1);table.getDefaultCell().setHorizontalAlignment(1);// 第一行table.addCell(createCenteredCellForTable("主要项目", 30, new Color(242, 247, 255), titleFont2, null, null));table.addCell(createCenteredCellForTable("项目配分", 0, new Color(242, 247, 255), titleFont2, null, null));table.addCell(createCenteredCellForTable("实际得分", 0, new Color(242, 247, 255), titleFont2, null, null));// 计数int[] projectSeq = {0};// 添加一级项目final BigDecimal[] allScore = {BigDecimal.ZERO}; // 审核分数合计final BigDecimal[] allGetScore = {BigDecimal.ZERO}; // 审核得分projectMap.forEach((projectId, projectName) -> {projectSeq[0]++;// 1转一RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(Locale.CHINA, RuleBasedNumberFormat.SPELLOUT);String result = formatter.format(projectSeq[0]);PdfPCell cell1 = setCell(3f, 1f, 1, result + "、" + projectName);// 获取对应项目的总分和得分BigDecimal eo45ProjectScoreAll = projectCollection.stream().filter(e -> projectId.equals(e.getString("eo45_project_id"))).map(e -> e.getBigDecimal("eo45_project_scoreall")).findFirst().orElse(BigDecimal.ZERO);allScore[0] = allScore[0].add(eo45ProjectScoreAll);BigDecimal eo45ProjectScore = projectCollection.stream().filter(e -> projectId.equals(e.getString("eo45_project_id"))).map(e -> e.getBigDecimal("eo45_project_score")).findFirst().orElse(BigDecimal.ZERO);allGetScore[0] = allGetScore[0].add(eo45ProjectScore);PdfPCell cell2 = new PdfPCell(new Paragraph(String.valueOf(eo45ProjectScoreAll.setScale(2, RoundingMode.HALF_UP)), contentFont));PdfPCell cell3 = new PdfPCell(new Paragraph(String.valueOf(eo45ProjectScore.setScale(2, RoundingMode.HALF_UP)), contentFont));//单元格对齐方式水平、垂直tableCellStyle(cell1, new Color(237, 239, 240), new Color(242, 247, 255), null);cell1.setFixedHeight(20);tableCellStyle(cell2, new Color(237, 239, 240), new Color(242, 247, 255), null);tableCellStyle(cell3, new Color(237, 239, 240), new Color(242, 247, 255), null);table.addCell(cell1);table.addCell(cell2);table.addCell(cell3);// 项目下添加二级分类int sortSeq = 0;for (DynamicObject categorysDynamicObject : projectCollection) {if (projectId.equals(categorysDynamicObject.getString("eo45_project_id"))) {sortSeq++;PdfPCell cell4 = setCell(3f, 1f, 1, projectSeq[0] + "." + sortSeq + " " + categorysDynamicObject.getString("eo45_sort_name"));PdfPCell cell5 = new PdfPCell(new Paragraph(String.valueOf(categorysDynamicObject.getBigDecimal("eo45_sort_scoreall").setScale(2, RoundingMode.HALF_UP)), contentFont));PdfPCell cell6 = new PdfPCell(new Paragraph(String.valueOf(categorysDynamicObject.getBigDecimal("eo45_sort_score").setScale(2, RoundingMode.HALF_UP)), contentFont));tableCellStyle(cell4, new Color(237, 239, 240), null, null);cell4.setFixedHeight(20);tableCellStyle(cell5, new Color(237, 239, 240), null, null);tableCellStyle(cell6, new Color(237, 239, 240), null, null);table.addCell(cell4);table.addCell(cell5);table.addCell(cell6);}}});// 添加分汇总PdfPCell cell4 = new PdfPCell(new Paragraph("审核分合计", titleFont));PdfPCell cell5 = new PdfPCell(new Paragraph(String.valueOf(allScore[0].setScale(2, RoundingMode.HALF_UP)), titleFont));PdfPCell cell6 = new PdfPCell(new Paragraph(String.valueOf(allGetScore[0].setScale(2, RoundingMode.HALF_UP)), titleFont));tableCellStyle(cell4, new Color(237, 239, 240), new Color(242, 247, 255), null);cell4.setFixedHeight(20);tableCellStyle(cell5, new Color(237, 239, 240), new Color(242, 247, 255), null);tableCellStyle(cell6, new Color(237, 239, 240), new Color(242, 247, 255), null);table.addCell(cell4);table.addCell(cell5);table.addCell(cell6);}private void handleTableOne(DynamicObject accessReportDO, PdfPTable table) {// 项目分类集合DynamicObjectCollection projectCollection = accessReportDO.getDynamicObjectCollection("eo45_report_projects");// 获取“否决项”数据DynamicObject oneProject = projectCollection.stream().filter(e -> "0".equals(e.getString("eo45_project_seq"))).collect(Collectors.toList()).get(0);DynamicObjectCollection contents = oneProject.getDynamicObjectCollection("eo45_report_contents");// 段落在其上方留出的空间量table.setSpacingBefore(10f);// 距离下方空间table.setSpacingAfter(20f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.setHeaderRows(1);table.getDefaultCell().setHorizontalAlignment(1);// 第一行table.addCell(createCenteredCellForTable("序号", 30, new Color(242, 247, 255), titleFont2, null, null));table.addCell(createCenteredCellForTable("关键领域", 0, new Color(242, 247, 255), titleFont2, null, null));table.addCell(createCenteredCellForTable("检查项目内容", 0, new Color(242, 247, 255), titleFont2, null, null));table.addCell(createCenteredCellForTable("是/否", 0, new Color(242, 247, 255), titleFont2, null, null));// 数据for (int i = 0; i < contents.size(); i++) {PdfPCell cell1 = new PdfPCell(new Paragraph(String.valueOf(i + 1), contentFont));PdfPCell cell2 = setCell(3f, 1f, 1, contents.get(i).getString("eo45_import_area"));// 富文本处理String contentContext = "";if (StringUtils.isNotBlank(contents.get(i).getString("eo45_project_context"))) {org.jsoup.nodes.Document documentResult = Jsoup.parse(contents.get(i).getString("eo45_project_context"));contentContext = documentResult.text();}PdfPCell cell3 = setCell(3f, 1f, 1, contentContext);// 获取选项JSONArray optionJsonArray = JSONArray.parseArray(contents.get(i).getString("eo45_option_json_tag"));String selectContent = "";if (optionJsonArray != null && !optionJsonArray.isEmpty()) {for (int j = 0; j < optionJsonArray.size(); j++) {JSONObject optionJson = optionJsonArray.getJSONObject(j);if (optionJson.getInteger("choose") == 1) {selectContent = optionJson.getString("options_content");break;}}}PdfPCell cell4 = setCell(3f, 1f, 1, selectContent);tableCellStyle(cell1, new Color(237, 239, 240), null, null);//单元格对齐方式水平、垂直cell1.setFixedHeight(20);tableCellStyle(cell2, new Color(237, 239, 240), null, null);tableCellStyle(cell3, new Color(237, 239, 240), null, null);tableCellStyle(cell4, new Color(237, 239, 240), null, null);table.addCell(cell1);table.addCell(cell2);table.addCell(cell3);table.addCell(cell4);}}private void buildAuditResult(Document document, DynamicObject entryResults) throws DocumentException {// 设置标题document.add(createTitle("审核结论"));// 设置两列float[] widths = {20f, 80f};PdfPTable table = new PdfPTable(widths);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.addCell(createCenteredCell("业务审核意见:", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_audit_conclusion_bus"), 0, null, contentFont));table.addCell(createCenteredCell("研发审核意见:", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_audit_conclusion_dev"), 0, null, contentFont));table.addCell(createCenteredCell("质量审核意见:", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_audit_conclusion_qu"), 0, null, contentFont));table.addCell(createCenteredCell("数字化能力评估审核意见:", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_audit_advice"), 0, null, contentFont));table.addCell(createCenteredCell("综合意见:", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_audit_conclusion_res"), 0, null, contentFont));document.add(table);}private void buildAuditScore(Document document, DynamicObject entryResults) throws DocumentException {// 设置标题document.add(createTitle("审核得分"));PdfPTable table = new PdfPTable(1);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);String scoreStr = "";if (StringUtils.isNotBlank(entryResults.getString("eo45_audit_scorestr"))) {org.jsoup.nodes.Document documentResult = Jsoup.parse(entryResults.getString("eo45_audit_scorestr"));scoreStr = documentResult.text();}table.addCell(createCenteredCell(scoreStr, 0, null, contentFont));document.add(table);}private void buildAuditData(Document document, DynamicObject entryResults) throws DocumentException {// 设置标题document.add(createTitle("审核方背景资料"));PdfPTable table = new PdfPTable(1);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.addCell(createCenteredCell(entryResults.getString("eo45_audit_information"), 0, null, contentFont));document.add(table);}private void buildAuditMethod(Document document, DynamicObject entryResults) throws DocumentException {// 设置标题document.add(createTitle("审核方法"));PdfPTable table = new PdfPTable(1);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.addCell(createCenteredCell(entryResults.getString("eo45_audit_method"), 0, null, contentFont));document.add(table);}private void buildAuditContent(Document document, DynamicObject entryResults) throws DocumentException {// 设置标题document.add(createTitle("审核内容"));PdfPTable table = new PdfPTable(1);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.addCell(createCenteredCell(entryResults.getString("eo45_audit_context"), 0, null, contentFont));document.add(table);}private void buildAuditRange(Document document, DynamicObject entryResults) throws DocumentException {// 设置标题document.add(createTitle("审核范围"));PdfPTable table = new PdfPTable(1);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.addCell(createCenteredCell(entryResults.getString("eo45_audit_scope"), 0, null, contentFont));document.add(table);}private void buildAuditType(Document document, DynamicObject data) throws DocumentException {// 设置标题document.add(createTitle("审核类型"));float[] widths = {2f, 8f, 2f, 8f, 2f, 8f, 70f};PdfPTable table = new PdfPTable(widths);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);PdfPCell cell = createCenteredCell("准入审核", 0, null, contentFont);PdfPCell cell2 = new PdfPCell();// 添加复选框绘制事件到单元格if ("0".equals(data.getString("eo45_report_type"))) {cell2.setCellEvent(new CheckBoxCellEvent());} else {cell2.setCellEvent(new CheckBoxCellNotEvent());}cell2.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);cell2.setBorder(Rectangle.NO_BORDER);table.addCell(cell2);table.addCell(cell);PdfPCell cell3 = createCenteredCell("年度审核", 0, null, contentFont);PdfPCell cell4 = new PdfPCell();// 添加复选框绘制事件到单元格if ("1".equals(data.getString("eo45_report_type"))) {cell4.setCellEvent(new CheckBoxCellEvent());} else {cell4.setCellEvent(new CheckBoxCellNotEvent());}cell4.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);cell4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);cell4.setBorder(Rectangle.NO_BORDER);table.addCell(cell4);table.addCell(cell3);PdfPCell cell5 = createCenteredCell("跟踪审核", 0, null, contentFont);PdfPCell cell6 = new PdfPCell();// 添加复选框绘制事件到单元格if ("2".equals(data.getString("eo45_report_type"))) {cell6.setCellEvent(new CheckBoxCellEvent());} else {cell6.setCellEvent(new CheckBoxCellNotEvent());}cell6.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);cell6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);cell6.setBorder(Rectangle.NO_BORDER);table.addCell(cell6);table.addCell(cell5);PdfPCell cell7 = new PdfPCell();cell7.setBorder(Rectangle.NO_BORDER);table.addCell(cell7);document.add(table);}private void buildAuditAim(Document document, DynamicObject entryResults) throws DocumentException {// 设置标题document.add(createTitle("审核目的"));PdfPTable table = new PdfPTable(1);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.addCell(createCenteredCell(entryResults.getString("eo45_audit_purpose"), 0, null, contentFont));document.add(table);}private void buildBasicInformation(Document document, DynamicObject entryResults) throws DocumentException {// 设置标题document.add(createTitle("基本信息"));// 设置两列float[] widths = {17f, 83f};PdfPTable table = new PdfPTable(widths);// 段落在其上方留出的空间量table.setSpacingBefore(5f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.addCell(createCenteredCell("审核对象", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_audit_obj"), 0, null, contentFont));table.addCell(createCenteredCell("审核地址", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_audit_addr"), 0, null, contentFont));table.addCell(createCenteredCell("审核日期", 15, null, contentFont));table.addCell(createCenteredCell(format.format(entryResults.getDate("eo45_audit_date")), 0, null, contentFont));table.addCell(createCenteredCell("审核人员", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_audit_person"), 0, null, contentFont));table.addCell(createCenteredCell("被审核方人员", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_beaudited_person"), 0, null, contentFont));table.addCell(createCenteredCell("本次审核后评级", 15, null, contentFont));table.addCell(createCenteredCell(entryResults.getString("eo45_score") + "级", 0, null, contentFont));document.add(table);}/*** 标题样式** @param value 标题* @return*/public PdfPTable createTitle(String value) {PdfPTable table = new PdfPTable(1);// 段落在其上方留出的空间量table.setSpacingBefore(5f);if ("基本信息".equals(value)) {table.setSpacingBefore(15f);}table.setWidthPercentage(100.0F);table.addCell(createCenteredCell(value, 20, new Color(242, 247, 255), titleFont));return table;}/*** 创建cell基本内容** @param value 值* @param fixedHeight 高度* @param color 背景色* @param font 字体样式* @return*/public PdfPCell createCenteredCell(String value, float fixedHeight, Color color, Font font) {Paragraph paragraph = new Paragraph(value, font);// 设置行高paragraph.setLeading(3f, 1);PdfPCell cell = new PdfPCell();// 重点--这样行高才生效cell.addElement(paragraph);// 水平对齐cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);// 垂直对齐// cell.setVerticalAlignment(Element.ALIGN_MIDDLE);// 边框cell.setBorder(Rectangle.NO_BORDER);// 设置背景色if (color != null) {cell.setBackgroundColor(color);}// 设置单元格高度if (fixedHeight != 0) {cell.setFixedHeight(fixedHeight);}return cell;}/*** 表格表头** @param value* @param fixedHeight* @param color* @param font* @return*/private PdfPCell createCenteredCellForTable(String value, float fixedHeight, Color color, Font font, String border, String alignment) {PdfPCell cell = new PdfPCell(new Paragraph(value, font));cell.setHorizontalAlignment(Element.ALIGN_LEFT);if ("center".equals(alignment)) {cell.setHorizontalAlignment(Element.ALIGN_CENTER);}cell.setVerticalAlignment(Element.ALIGN_MIDDLE);cell.setBorderColor(new Color(230, 230, 230));if (border == null) {cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);}// 设置背景色if (color != null) {cell.setBackgroundColor(color);}// 设置单元格高度if (fixedHeight != 0) {cell.setFixedHeight(fixedHeight);}return cell;}/*** 设置单元格样式** @param cell*/private void tableCellStyle(PdfPCell cell, Color borderColor, Color backgroundColor, String border) {cell.setHorizontalAlignment(Element.ALIGN_LEFT);cell.setVerticalAlignment(Element.ALIGN_MIDDLE);// 只显示上下边框if (border == null) {cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);}// 边框颜色if (borderColor != null) {cell.setBorderColorTop(borderColor);cell.setBorderColorBottom(borderColor);}// 背景色if (backgroundColor != null) {cell.setBackgroundColor(backgroundColor);}cell.setBorderColor(new Color(230, 230, 230));}/*** 设置行高** @param v 固定间距值* @param v1 多倍间距值* @param rowspan 合并行数* @param value 值*/private PdfPCell setCell(float v, float v1, int rowspan, Object value) {PdfPCell cell = new PdfPCell();Paragraph paragraph = new Paragraph(String.valueOf(value), contentFont);paragraph.setLeading(v, v1);cell.addElement(paragraph);if (rowspan > 1) {cell.setRowspan(rowspan);}cell.setPaddingBottom(3f);return cell;}}
头部添加水印/图片工具类
package xcsy.zjy.webapi.utils;import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;import java.io.IOException;
import java.net.URL;/*** @program: xcsy-cosmic* @description: pdf添加头部水印图片* @author: lyw* @create: 2025-02-17 16:51**/public class AddImageToEachPageHeader extends PdfPageEventHelper {private static final Log log = LogFactory.getLog(AddImageToEachPageHeader.class);// 图片路径public static final String IMG = "img/logo.png";// 图片路径public static final String LINEIMG = "img/line.png";// 自定义页面事件监听器Image headerImage;Image lineImage;public AddImageToEachPageHeader() throws IOException, DocumentException {URL resourceUrl = AddImageToEachPageHeader.class.getClassLoader().getResource(IMG);assert resourceUrl != null;headerImage = Image.getInstance(resourceUrl);// scaleToFit按比例缩放图像、调整大小以适应您的需求headerImage.scaleToFit(50, 50);URL resourceUrl2 = AddImageToEachPageHeader.class.getClassLoader().getResource(LINEIMG);assert resourceUrl2 != null;lineImage = Image.getInstance(resourceUrl2);}@Overridepublic void onEndPage(PdfWriter writer, Document document) {try {// 计算图片1放置的位置// float x = (document.right() - document.left()) / 2 + document.leftMargin() - headerImage.getScaledWidth() / 2; // 居中float x = document.leftMargin();// 适当调整距离顶部的距离float y = document.top() + headerImage.getScaledHeight() + 10;headerImage.setAbsolutePosition(x, y);writer.getDirectContent().addImage(headerImage);// 图2// 获取页面宽度float pageWidth = document.getPageSize().getWidth();float x2 = 0;// 适当调整距离顶部的距离float y2 = document.top() + headerImage.getScaledHeight();// scaleAbsolute直接设置图像的确切宽度和高度,不考虑原始宽高比。lineImage.scaleAbsolute(pageWidth, 10);lineImage.setAbsolutePosition(x2, y2);writer.getDirectContent().addImage(lineImage);} catch (DocumentException e) {log.error("pdf添加头部水印图片DocumentException:{}", e);}}}
复选框(选中)绘制工具类
package xcsy.zjy.webapi.utils;import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;import java.awt.*;/*** @program: xcsy-cosmic* @description: pdf复选框* @author: lyw* @create: 2025-02-18 10:30**/public class CheckBoxCellEvent implements PdfPCellEvent {@Overridepublic void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];// 绘制复选框的位置和大小float x = position.getLeft() + 2; // X坐标,相对于单元格左下角float y = position.getBottom() + 2; // Y坐标,相对于单元格左下角float size = 10; // 复选框大小// 开始写入操作canvas.saveState();// 绘制复选框canvas.rectangle(x, y, size, size);canvas.setColorStroke(new Color( 190, 198, 205));canvas.stroke();// 确保勾选标记的起点、中点和终点位置合理,以形成一个清晰的√符号float rotatedMarkStartX = x + size - 2; // 原始markStartX关于x轴+size的对称点float rotatedMarkStartY = y + size - ((size / 2) - 2); // 原始markStartY关于y轴+size的对称点float rotatedMarkMidX = x + size - (size / 2); // 原始markMidX关于x轴+size的对称点float rotatedMarkMidY = y + 3; // 原始markMidY关于y轴+size的对称点float rotatedMarkEndX = x + 2; // 原始markEndX关于x轴+size的对称点float rotatedMarkEndY = y + size - 4; // 原始markEndY关于y轴+size的对称点canvas.moveTo(rotatedMarkStartX, rotatedMarkStartY); // 设置旋转后的起点canvas.lineTo(rotatedMarkMidX, rotatedMarkMidY); // 经过旋转后的中间点canvas.lineTo(rotatedMarkEndX, rotatedMarkEndY); // 结束于旋转后的右上角canvas.setColorStroke(new Color(0, 103, 255));canvas.setColorFill(new Color(0, 103, 255));canvas.stroke();// 结束写入操作canvas.restoreState();}
}
复选框(不选中)绘制工具类
package xcsy.zjy.webapi.utils;import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;import java.awt.*;/*** @program: xcsy-cosmic* @description: pdf复选框(不选中)* @author: lyw* @create: 2025-02-18 10:30**/public class CheckBoxCellNotEvent implements PdfPCellEvent {@Overridepublic void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];// 绘制复选框的位置和大小float x = position.getLeft() + 2; // X坐标,相对于单元格左下角float y = position.getBottom() + 2; // Y坐标,相对于单元格左下角float size = 10; // 复选框大小// 开始写入操作canvas.saveState();// 绘制复选框canvas.rectangle(x, y, size, size);canvas.setColorStroke(new Color( 190, 198, 205));canvas.stroke();// 结束写入操作canvas.restoreState();}
}
页码工具类
package xcsy.zjy.webapi.utils;import com.lowagie.text.*;
import com.lowagie.text.pdf.*;import java.io.IOException;/*** @Author xx* @Date 2023/12/15 10:05* @Description: 导出pdf添加页数* @Version 1.0*/
public class PdfPageUtil extends PdfPageEventHelper {/*** 页眉*///public String header = "itext测试页眉";/*** 文档字体大小,页脚页眉最好和文本大小一致*/public int presentFontSize = 9;/*** 文档页面大小,最好前面传入,否则默认为A4纸张*/public Rectangle pageSize = PageSize.A4;// 模板public PdfTemplate total;// 基础字体对象public BaseFont bf = null;// 利用基础字体生成的字体对象,一般用于生成中文文字public Font fontDetail = null;/**** 无参构造方法.**/public PdfPageUtil() {}/**** 构造方法.** @param** @param presentFontSize* 数据体字体大小* @param pageSize* 页面文档大小,A4,A5,A6横转翻转等Rectangle对象*/public PdfPageUtil( int presentFontSize, Rectangle pageSize) {this.presentFontSize = presentFontSize;this.pageSize = pageSize;}public void setPresentFontSize(int presentFontSize) {this.presentFontSize = presentFontSize;}/**** 文档打开时创建模板*/@Overridepublic void onOpenDocument(PdfWriter writer, Document document) {// 共 页 的矩形的长宽高total = writer.getDirectContent().createTemplate(50, 50);}/****关闭每页的时候,写入页眉,写入'第几页共'这几个字。*/@Overridepublic void onEndPage(PdfWriter writer, Document document) {this.addPage(writer, document);}//加分页public void addPage(PdfWriter writer, Document document){//设置分页页眉页脚字体try {if (bf == null) {bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);}if (fontDetail == null) {fontDetail = new Font(bf, presentFontSize, Font.NORMAL);// 数据体字体}} catch (DocumentException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}// 1.写入页眉
// ColumnText.showTextAligned(writer.getDirectContent(),
// Element.ALIGN_LEFT, new Phrase(header, fontDetail),
// document.left(), document.top() + 20, 0);// 2.写入前半部分的 第 X页/共int pageS = writer.getPageNumber();//String foot1 = "第 " + pageS + " 页 /共";String foot1 = pageS +"/";Phrase footer = new Phrase(foot1, fontDetail);// 3.计算前半部分的foot1的长度,后面好定位最后一部分的'Y页'这俩字的x轴坐标,字体长度也要计算进去 = lenfloat len = bf.getWidthPoint(foot1, presentFontSize);// 4.拿到当前的PdfContentBytePdfContentByte cb = writer.getDirectContent();// 5.写入页脚1,x轴就是(右margin+左margin + right() -left()- len)/2.0FColumnText.showTextAligned(cb,Element.ALIGN_CENTER,footer,(document.rightMargin() + document.right()+ document.leftMargin() - document.left() - len) / 2.0F ,document.bottom() - 10, 0);cb.addTemplate(total, (document.rightMargin() + document.right()+ document.leftMargin() - document.left()) / 2.0F ,document.bottom() - 10); // 调节模版显示的位置}// //加水印
// public void addWatermark(PdfWriter writer){
// // 水印图片
// Image image;
// try {
// image = Image.getInstance("./web/images/001.jpg");
// PdfContentByte content = writer.getDirectContentUnder();
// content.beginText();
// // 开始写入水印
// for(int k=0;k<5;k++){
// for (int j = 0; j <4; j++) {
// image.setAbsolutePosition(150*j,170*k);
// content.addImage(image);
// }
// }
// content.endText();
// } catch (IOException | DocumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }/**** 关闭文档时,替换模板,完成整个页眉页脚组件*/@Overridepublic void onCloseDocument(PdfWriter writer, Document document) {// 关闭文档的时候,将模板替换成实际的 Y 值total.beginText();// 生成的模版的字体、颜色total.setFontAndSize(bf, presentFontSize);//页脚内容拼接 如 第1页/共2页//String foot2 = " " + (writer.getPageNumber()) + " 页";//页脚内容拼接 如 第1页/共2页String foot2 = String.valueOf(writer.getPageNumber() - 1);// 模版显示的内容total.showText(foot2);total.endText();total.closePath();}
}
最后大致效果图


静态图片文件存放位置项目下:

相关文章:
lowagie(itext)老版本手绘PDF,包含页码、水印、图片、复选框、复杂行列合并、行高设置等。
入口类:exportPdf package xcsy.qms.webapi.service;import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.common.utils.StringUtils; import com.ibm.icu.text.RuleBasedNumberFormat; import com.lowagie…...
第002文-kali虚拟机安全与网络配置
1、kali系统介绍 kali是一个基于Linux kernel的操作系统,由BackTrack(简称BT)发展而来。BackTrack是2006年推出的一个用于渗透测试及黑客攻防的专用平台,基于Knoppix(linux的一个发行版)开发。BackTrack版本周期:2006年的起始版本BackTrack …...
软件工程复试专业课-软件生命周期
文章目录 软件过程模型瀑布模型模型图特点优缺点改进后的瀑布模型 快速原型模型模型图优缺点 增量模型(迭代-递增模型)原型图与瀑布和快速原型的区别优缺点风险更大的增量模型 螺旋模型简介模型图优缺点 喷泉模型模型图优缺点 编码修补模型敏捷过程优缺点…...
DILLEMA:扩散模型+大语言模型,多模态数据增强框架
引言:深度学习模型的鲁棒性测试需要全面且多样化的测试数据。现有的方法通常基于简单的数据增强技术或生成对抗网络,但这些方法在生成真实且多样化的测试数据集方面存在局限性。为了克服这些限制,DILLEMA框架应运而生,旨在通过结合…...
OpenBMC:BmcWeb app获取socket
OpenBMC:BmcWeb app.run-CSDN博客 app对象在run函数中调用了setupSocket() static std::vector<Acceptor> setupSocket() {std::vector<Acceptor> acceptors;char** names = nullptr;int listenFdCount = sd_listen_fds_with_names(0, &names);BMCWEB_LOG_DE…...
突破加速度计的精度与量程瓶颈:HEROS-GAN技术
在当今科技飞速发展的背景下,低成本传感器的应用范围日益扩大。然而,低成本加速度计由于其固有的限制——如信号噪声显著和动态范围狭窄——往往难以满足高精度应用场景的需求。哈尔滨工业大学的研究团队最近提出了一项名为HEROS-GAN(Honed-E…...
C++程序员内功修炼——Linux C/C++编程技术汇总
在软件开发的宏大版图中,C 语言宛如一座巍峨的高山,吸引着无数开发者攀登探索。而 Linux 操作系统,以其开源、稳定、高效的特性,成为了众多开发者钟爱的开发平台。将 C 与 Linux 相结合,就如同为开发者配备了一把无坚不…...
苍穹外卖-阿里云OSS文件上传
苍穹外卖-阿里云OSS文件上传 一、阿里云OSS简介**获取AccessKey**获取enpoint 二、代码实现1 引入依赖2 定义OSS相关配置2.1 application-dev.yml2.2 application.yml 3 读取OSS配置3.1 AliOssProperties 4 生成OSS工具类对象4.1 AliOssUtil4.2 OssConfiguration2.5 CommonCont…...
C# 中 Array、ArrayList 和 List 的比较
C# 中 Array、ArrayList 和 List 的比较 在 C# 中,Array、ArrayList 和 List<T> 都用于存储和管理数据集合,但它们在类型安全性、性能、灵活性和使用场景上存在显著差异。以下是对这三种集合的详细比较: 1. 概述 特性ArrayArrayList…...
DeepSeek 提示词:常见指令类型
🧑 博主简介:CSDN博客专家,历代文学网(PC端可以访问:https://literature.sinhy.com/#/?__c1000,移动端可微信小程序搜索“历代文学”)总架构师,15年工作经验,精通Java编…...
商业AI模型新篇章:Granite 3.2引领行业创新
摘要 Granite 3.2 是一款专为商业环境设计的人工智能模型,旨在提高AI驱动应用的信任度和可扩展性。该模型从零开始构建,采用最新的密集型架构,支持12种语言,覆盖11个不同领域。通过其先进的技术,Granite 3.2 不仅增强了…...
Spring boot中的@ConfigurationProperties注解
Spring boot中的ConfigurationProperties注解 ConfigurationProperties 是 Spring Boot 提供的一个强大注解,用于将配置文件(如 application.properties 或 application.yml)中的配置绑定到一个 Java 对象中。它不仅简化了配置管理ÿ…...
Rust中的异步编程:构建简单的网页爬虫
一、什么是Rust中的Futures和Async? 在Rust中,异步编程基于future(未来)的概念。一个future表示一个当前可能不可用,但将来某个时候可以获得的值。Rust中的Future特征定义了这一概念,任何实现了该特征的类…...
springai系列(二)从0开始搭建和接入azure-openai实现智能问答
文章目录 前言1.从0开始搭建项目2.进入微软openai申请key3.配置application.yaml4.编写controller5.测试源码下载地址总结 前言 之前使用openai的官网的api需要科学上网,但是我们可以使用其他的代理间接实现使用chatgpt的相关模型,解决这个问题。比如:本…...
flutter 局部刷新控件Selector源码实现原理
Flutter 中的 Selector 组件是 provider 包提供的一个优化工具,用于在状态管理中仅选择所需数据片段,避免不必要的 Widget 重建。其实现原理基于以下几个关键点: 1. 核心设计目标 选择性重建:仅当特定数据变化时触发 Widget 重建&…...
Eclipse 编译项目指南
Eclipse 编译项目指南 引言 Eclipse 是一款功能强大的集成开发环境(IDE),广泛用于Java、C/C、Python等多种编程语言的开发。在Eclipse中编译项目是进行软件开发的基础步骤。本文将详细介绍如何在Eclipse中编译项目,包括项目设置…...
Go在1.22版本修复for循环陷阱
记录 前段时间升级Go版本碰到一个大坑,先记录。 先上代码案例: func main() {testClosure() }func testClosure() {for i : 0; i < 5; i {defer func() {fmt.Println(i)}()} }在1.22之下(不包括1.22)版本: 输出的…...
c++_sort函数
sort介绍 在C/C中,要想应用排序算法,可以使用c语言的qsort,也可以使用c的sort 。 1)qsort 是 C 标准库提供的一个通用排序函数,位于 stdlib.h 头文件中。 qsort 适用于 C 语言中的数组。 2)sort 是 C 中STL的泛型算法…...
【Stable Diffusion】AnimatedDiff--AI动画 插件使用技巧分享;文生视频、图生视频、AI生成视频工具;
本专栏主要记录人工智能的应用方面的内容,包括chatGPT、DeepSeek、AI绘画等等; 在当今AI的热潮下,不学习AI,就要被AI淘汰;所以欢迎小伙伴加入本专栏和我一起探索AI的应用,通过AI来帮助自己提升生产力; 本文的目标就是让每一个读者,都能学会并掌握AnimateDiff的使用;成…...
可视化约瑟夫生死环小游戏
这是一个基于Tkinter的图形界面应用程序,用于模拟约瑟夫环问题。约瑟夫环问题是一个经典的数学问题,描述的是N个人围成一圈,从第一个人开始报数,每数到第M个人就将其淘汰,然后从下一个人继续报数,直到剩下最…...
【深入理解JWT】从认证授权到网关安全
最近的项目学习中,在进行登陆模块的用户信息验证这一部分又用到了JWT的一些概念和相关知识,特在此写了这篇文章、方便各位笔者理解JWT相关概念 目录 先来理解JWT是什么? 区分有状态认证和无状态认证 有状态认证 VS 无状态认证 JWT令牌的…...
学习路之PHP --TP6异步执行功能 (无需安装任何框架)
学习路之PHP --异步执行功能 (无需安装任何框架) 简介一、工具类二、调用三、异步任务的操作四、效果: 简介 执行异步任务是一种很常见的需求,如批量发邮箱,短信等等执行耗时任务时,需要程序异步执行&…...
DeepSeek-R1:GPU编程自动化加速的新纪元
摘要 DeepSeek-R1是由斯坦福大学和普林斯顿大学研究者共同开发的项目,其自研的CUDA核心在性能测试中取得了卓越成绩,超越了o1和Claude 3.5 Sonnet,位居榜首。尽管DeepSeek-R1目前仅在约20%的任务中实现了对PyTorch Eager模式的性能超越&#…...
CSS 对齐:深入理解与技巧实践
CSS 对齐:深入理解与技巧实践 引言 在网页设计中,元素的对齐是至关重要的。一个页面中元素的对齐方式直接影响到页面的美观度和用户体验。CSS 提供了丰富的对齐属性,使得开发者可以轻松实现各种对齐效果。本文将深入探讨 CSS 对齐的原理、方法和技巧,帮助开发者更好地掌握…...
vue深拷贝:1、使用JSON.parse()和JSON.stringify();2、使用Lodash库;3、使用深拷贝函数(采用递归的方式)
文章目录 引言三种方法的优缺点在Vue中,实现数组的深拷贝I JSON.stringify和 JSON.parse的小技巧深拷贝步骤缺点:案例1:向后端请求路由数据案例2: 表单数据处理时复制用户输入的数据II 使用Lodash库步骤适用于复杂数据结构和需要处理循环引用的场景III 自定义的深拷贝函数(…...
九、数据治理架构流程
一、总体结构 《数据治理架构流程图》(Data Governance Architecture Flowchart) 水平结构:流程图采用水平组织,显示从数据源到数据应用的进程。 垂直结构:每个水平部分进一步划分为垂直列,代表数据治理的…...
【数据结构】 最大最小堆实现优先队列 python
堆的定义 堆(Heap)是一种特殊的完全二叉树结构,通常分为最大堆和最小堆两种类型。 在最大堆中,父节点的值总是大于或等于其子节点的值; 而在最小堆中,父节点的值总是小于或等于其子节点的值。 堆常用于实…...
51c自动驾驶~合集52
我自己的原文哦~ https://blog.51cto.com/whaosoft/13383340 #世界模型如何推演未来的千万种可能 驾驶世界模型(DWM),专注于预测驾驶过程中的场景演变,已经成为追求自动驾驶的一种有前景的范式。这些方法使自动驾驶系统能够更…...
服务 ‘Sql Server VSS writer‘ (SQLWriter) 在安装 LocalDB 时无法启动
安装Microsoft Visual C 2015-2019 Redistributable (x64)...
【我的 PWN 学习手札】House of Husk
House of Husk House of Husk是利用格式化输出函数如printf、vprintf在打印输出时,会解析格式化字符如%x、%lld从而调用不同的格式化打印方法(函数)。同时C语言还提供了注册自定义格式化字符的方法。注册自定义格式化字符串输出方法…...
