|
|
@@ -1,12 +1,14 @@
|
|
|
package com.xunmei.file.utils;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.lowagie.text.*;
|
|
|
import com.lowagie.text.pdf.*;
|
|
|
import com.xunmei.file.vo.ItextPdfTableVo;
|
|
|
import com.xunmei.file.vo.PdfFilePathVo;
|
|
|
+import com.xunmei.system.api.domain.AccessDataVo;
|
|
|
import com.xunmei.system.api.domain.CheckDataVo;
|
|
|
import com.xunmei.system.api.domain.ResumptionPdf;
|
|
|
import com.xunmei.system.api.domain.SafeCheckTaskRegisterBookVo;
|
|
|
@@ -144,6 +146,19 @@ public class PdfUtil {
|
|
|
document.add(p);
|
|
|
}
|
|
|
|
|
|
+ public static void dealEduHeader(PdfPTable table, BaseFont fs, String title, int fontSize) {
|
|
|
+ //文件title
|
|
|
+ PdfPCell pdfPCell = new PdfPCell();
|
|
|
+ final Paragraph p = new Paragraph(new Chunk(title, new Font(fs, fontSize)));
|
|
|
+ p.setAlignment(Paragraph.ALIGN_CENTER);
|
|
|
+ // 文件title 段落下空白
|
|
|
+ p.setSpacingAfter(10f);
|
|
|
+ pdfPCell.setColspan(6);
|
|
|
+ pdfPCell.addElement(p);
|
|
|
+ pdfPCell.setBorder(Rectangle.BOTTOM);
|
|
|
+ table.addCell(pdfPCell);
|
|
|
+ }
|
|
|
+
|
|
|
public static void dealEduBody(Document document, PdfPTable table, Font tableFont, Map<String, Object> data) throws Exception {
|
|
|
//第一行
|
|
|
createPDFCell(tableFont, table, "时间", Element.ALIGN_MIDDLE, 1, 1);
|
|
|
@@ -157,29 +172,29 @@ public class PdfUtil {
|
|
|
createPDFCell(tableFont, table, data.get("recorderName").toString(), Element.ALIGN_MIDDLE, 2, 1);
|
|
|
|
|
|
//内容
|
|
|
- final PdfPCell pCell = createPDFCell(tableFont, table, "内容", Element.ALIGN_MIDDLE, 1, 140);
|
|
|
- pCell.setFixedHeight(100);
|
|
|
- final PdfPCell content = createPDFCell(tableFont, table, data.get("content").toString(), Element.ALIGN_MIDDLE, 5, 140);
|
|
|
- content.setFixedHeight(100);
|
|
|
+ createPDFCell(tableFont, table, "内容", Element.ALIGN_MIDDLE, 1, 140);
|
|
|
+ createPDFCell(tableFont, table, data.get("content").toString(), Element.ALIGN_LEFT, 5, 140);
|
|
|
createPDFCell(tableFont, table, "总结", Element.ALIGN_MIDDLE, 1, 140);
|
|
|
- createPDFCell(tableFont, table, data.get("note").toString(), Element.ALIGN_MIDDLE, 5, 140);
|
|
|
+ createPDFCell(tableFont, table, data.get("note").toString(), Element.ALIGN_LEFT, 5, 140);
|
|
|
createPDFCell(tableFont, table, "参会人员签字", Element.ALIGN_MIDDLE, 1, 140);
|
|
|
- final PdfPTable imageTable = getImage((List<String>) data.get("image"), 3, 100, 100, 3);
|
|
|
- //图片填充
|
|
|
- final PdfPCell cell = new PdfPCell();
|
|
|
- cell.setNoWrap(false);
|
|
|
- cell.setPaddingLeft(8f);
|
|
|
- cell.setPaddingRight(8f);
|
|
|
- cell.setPaddingBottom(8f);
|
|
|
- cell.setPaddingTop(8f);
|
|
|
- cell.setColspan(5);
|
|
|
- cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
- cell.addElement(imageTable);
|
|
|
- table.addCell(cell);
|
|
|
-
|
|
|
+ dealEduImageCell((List<String>) data.get("signImage"), table, 5, 30, 30);
|
|
|
document.add(table);
|
|
|
+
|
|
|
+ //第二页
|
|
|
+ //按6份等分图片数组,一页只显示6张
|
|
|
+ final List<List<String>> listList = ListUtil.split((List<String>) data.get("fileImage"), 6);
|
|
|
+ for (List<String> stringList : listList) {
|
|
|
+ PdfPTable innerTable = new PdfPTable(6);
|
|
|
+ createPDFCell(tableFont, innerTable, "图片附件", Element.ALIGN_MIDDLE, 1, 1);
|
|
|
+ innerTable.setSpacingBefore(10f);
|
|
|
+ //一行展示一张图片
|
|
|
+ dealEduImageCell(new ArrayList<>(stringList), innerTable, 2, 150, 200);
|
|
|
+ document.newPage();
|
|
|
+ document.add(innerTable);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public static void dealResumptionBody(Document document, PdfPTable table, Font tableFont, Map<String, Object> data) throws Exception {
|
|
|
PdfUtil.createPDFCell(tableFont, table, "检查内容", Element.ALIGN_CENTER, 6, 0);
|
|
|
PdfUtil.createPDFCell(tableFont, table, "检查情况", Element.ALIGN_CENTER, 0, 0);
|
|
|
@@ -310,122 +325,110 @@ public class PdfUtil {
|
|
|
}
|
|
|
|
|
|
public static void dealDrillBody(Document document, PdfPTable table, Font tableFont, Map<String, Object> data) throws Exception {
|
|
|
- table.setSplitLate(false);
|
|
|
- table.setSplitRows(true);
|
|
|
//第一行
|
|
|
createPDFCell(tableFont, table, "演练单位", Element.ALIGN_CENTER, 1, 1);
|
|
|
createPDFCell(tableFont, table, data.get("orgName").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
createPDFCell(tableFont, table, "地点", Element.ALIGN_CENTER, 1, 1);
|
|
|
createPDFCell(tableFont, table, data.get("drillSite").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
//第二行
|
|
|
- createPDFCell(tableFont, table, "演练时间", Element.ALIGN_CENTER, 1, 1);
|
|
|
- createPDFCell(tableFont, table, data.get("drillTime").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
- createPDFCell(tableFont, table, "演练项目", Element.ALIGN_CENTER, 1, 1);
|
|
|
- createPDFCell(tableFont, table, data.get("typeText").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
- //第三行
|
|
|
createPDFCell(tableFont, table, "指挥人", Element.ALIGN_CENTER, 1, 1);
|
|
|
createPDFCell(tableFont, table, data.get("hostName").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
createPDFCell(tableFont, table, "记录人", Element.ALIGN_CENTER, 1, 1);
|
|
|
createPDFCell(tableFont, table, data.get("recorderName").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
-
|
|
|
+ //第三行
|
|
|
+ createPDFCell(tableFont, table, "演练时间", Element.ALIGN_CENTER, 1, 1);
|
|
|
+ createPDFCell(tableFont, table, data.get("drillTime").toString(), Element.ALIGN_LEFT, 5, 1);
|
|
|
+ createPDFCell(tableFont, table, "演练项目", Element.ALIGN_CENTER, 1, 1);
|
|
|
+ createPDFCell(tableFont, table, data.get("typeText").toString(), Element.ALIGN_LEFT, 5, 1);
|
|
|
//预设案由
|
|
|
- PdfPCell contentCell = new PdfPCell();
|
|
|
- contentCell.setColspan(6);
|
|
|
- final Paragraph presetCase = new Paragraph(new Chunk(data.get("presetCase").toString(), tableFont));
|
|
|
- presetCase.setSpacingAfter(8F);
|
|
|
- contentCell.addElement(presetCase);
|
|
|
- contentCell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
- table.addCell(contentCell);
|
|
|
- dealDrillImageCell(data.get("drillSituation").toString(), tableFont, (List<String>) data.get("imageData"), table);
|
|
|
- dealDrillImageCell("参会演练人员(签字):", tableFont, (List<String>) data.get("image"), table);
|
|
|
- /* //演练情况
|
|
|
- PdfPCell noteCell = new PdfPCell();
|
|
|
- noteCell.setColspan(6);
|
|
|
- Paragraph noteParagraph = new Paragraph(new Chunk(data.get("drillSituation").toString(), tableFont));
|
|
|
- noteParagraph.setSpacingAfter(8F);
|
|
|
- noteCell.addElement(noteParagraph);
|
|
|
- noteCell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
- final List<String> imageDataList = (List<String>) data.get("imageData");
|
|
|
- final int imageDataAddNums = imageDataList.size() % 3;
|
|
|
- for (int i = 0; i < 3 - imageDataAddNums; i++) {
|
|
|
- imageDataList.add("black.png");
|
|
|
- }
|
|
|
- PdfPTable imageDataInnerTable = new PdfPTable(3);
|
|
|
- for (String str : imageDataList) {
|
|
|
- Image imageData = convertFileToByteArray(new File(str));
|
|
|
- if (imageData != null) {
|
|
|
- imageData.scaleAbsolute(130, 130);
|
|
|
- }
|
|
|
- PdfPCell cell = new PdfPCell(imageData);
|
|
|
- cell.setBorder(Rectangle.NO_BORDER);
|
|
|
- cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
- cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
- imageDataInnerTable.addCell(cell);
|
|
|
- }
|
|
|
- noteCell.addElement(imageDataInnerTable);
|
|
|
- table.addCell(noteCell);
|
|
|
+ createPDFCell(tableFont, table, "预设案由", Element.ALIGN_MIDDLE, 1, 140);
|
|
|
+ createPDFCell(tableFont, table, data.get("presetCase").toString(), Element.ALIGN_LEFT, 5, 140);
|
|
|
+ //演练情况
|
|
|
+ createPDFCell(tableFont, table, "演练情况", Element.ALIGN_MIDDLE, 1, 140);
|
|
|
+ createPDFCell(tableFont, table, data.get("drillSituation").toString(), Element.ALIGN_LEFT, 5, 140);
|
|
|
+ //点评总结
|
|
|
+ createPDFCell(tableFont, table, "点评总结", Element.ALIGN_MIDDLE, 1, 140);
|
|
|
+ createPDFCell(tableFont, table, data.get("comment").toString(), Element.ALIGN_LEFT, 5, 140);
|
|
|
+ //参会人员签字
|
|
|
+ createPDFCell(tableFont, table, "参会人员签字", Element.ALIGN_MIDDLE, 1, 140);
|
|
|
+ dealEduImageCell((List<String>) data.get("signImage"), table, 5, 30, 30);
|
|
|
+ document.add(table);
|
|
|
|
|
|
+ //第二页
|
|
|
+ //按6份等分图片数组,一页只显示6张
|
|
|
+ final List<List<String>> listList = ListUtil.split((List<String>) data.get("fileImage"), 6);
|
|
|
+ for (List<String> stringList : listList) {
|
|
|
+ PdfPTable innerTable = new PdfPTable(6);
|
|
|
+ createPDFCell(tableFont, innerTable, "图片附件", Element.ALIGN_MIDDLE, 1, 1);
|
|
|
+ innerTable.setSpacingBefore(10f);
|
|
|
+ //一行展示一张图片
|
|
|
+ dealEduImageCell(new ArrayList<>(stringList), innerTable, 2, 150, 200);
|
|
|
+ document.newPage();
|
|
|
+ document.add(innerTable);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void dealDrillImageCell( List<String> imageList, PdfPTable table) throws Exception {
|
|
|
//签字区域
|
|
|
- PdfPCell signCell = new PdfPCell();
|
|
|
- signCell.setColspan(6);
|
|
|
- final Paragraph paragraph1 = new Paragraph(new Chunk("参会演练人员(签字):", tableFont));
|
|
|
- paragraph1.setSpacingAfter(8F);
|
|
|
- signCell.addElement(paragraph1);
|
|
|
- signCell.setBorder(Rectangle.LEFT | Rectangle.RIGHT);
|
|
|
- final List<String> imageList = (List<String>) data.get("image");
|
|
|
+ PdfPCell outCell = new PdfPCell();
|
|
|
+ outCell.setColspan(5);
|
|
|
+ outCell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
final int imageAddNums = imageList.size() % 3;
|
|
|
- for (int i = 0; i < 3 - imageAddNums; i++) {
|
|
|
- imageList.add("black.png");
|
|
|
+ if (imageAddNums != 0) {
|
|
|
+ for (int i = 0; i < 3 - imageAddNums; i++) {
|
|
|
+ imageList.add("black.png");
|
|
|
+ }
|
|
|
}
|
|
|
PdfPTable imageInnerTable = new PdfPTable(3);
|
|
|
- for (String str : imageList) {
|
|
|
- Image imageData = convertFileToByteArray(new File(str));
|
|
|
+ for (String image : imageList) {
|
|
|
+ Image imageData = convertFileToByteArray(new File(image));
|
|
|
if (imageData != null) {
|
|
|
- imageData.scaleAbsolute(130, 130);
|
|
|
+ imageData.scaleAbsolute(120, 120);
|
|
|
}
|
|
|
- PdfPCell cell = new PdfPCell(imageData);
|
|
|
- cell.setBorder(Rectangle.NO_BORDER);
|
|
|
- cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
- cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
- imageInnerTable.addCell(cell);
|
|
|
+ PdfPCell innerCell = new PdfPCell(imageData);
|
|
|
+ innerCell.setBorder(Rectangle.NO_BORDER);
|
|
|
+ innerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
+ innerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
+ imageInnerTable.addCell(innerCell);
|
|
|
}
|
|
|
- signCell.addElement(imageInnerTable);
|
|
|
- table.addCell(signCell);*/
|
|
|
-
|
|
|
-
|
|
|
- //点评总结
|
|
|
- PdfPCell commentCell = new PdfPCell();
|
|
|
- commentCell.setColspan(6);
|
|
|
- commentCell.addElement(new Paragraph(new Chunk(data.get("comment").toString(), tableFont)));
|
|
|
- table.addCell(commentCell);
|
|
|
- document.add(table);
|
|
|
+ outCell.addElement(imageInnerTable);
|
|
|
+ table.addCell(outCell);
|
|
|
}
|
|
|
|
|
|
- public static void dealDrillImageCell(String chunk, Font tableFont, List<String> imageList, PdfPTable table) throws Exception {
|
|
|
+ public static void dealEduImageCell(List<String> imageList, PdfPTable table, Integer imageNumsOfRow, Integer imageWith, Integer imageHigh) throws Exception {
|
|
|
//签字区域
|
|
|
PdfPCell outCell = new PdfPCell();
|
|
|
+ outCell.setNoWrap(false);
|
|
|
outCell.setColspan(6);
|
|
|
- final Paragraph paragraph1 = new Paragraph(new Chunk(chunk, tableFont));
|
|
|
- paragraph1.setSpacingAfter(8F);
|
|
|
- outCell.addElement(paragraph1);
|
|
|
- outCell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
- final int imageAddNums = imageList.size() % 3;
|
|
|
- for (int i = 0; i < 3 - imageAddNums; i++) {
|
|
|
- imageList.add("black.png");
|
|
|
+ // outCell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
+ final int imageAddNums = imageList.size() % imageNumsOfRow;
|
|
|
+ if (imageAddNums != 0) {
|
|
|
+ for (int i = 0; i < imageNumsOfRow - imageAddNums; i++) {
|
|
|
+ imageList.add("black.png");
|
|
|
+ }
|
|
|
}
|
|
|
- PdfPTable imageInnerTable = new PdfPTable(3);
|
|
|
+ PdfPTable imageInnerTable = new PdfPTable(imageNumsOfRow);
|
|
|
+ imageInnerTable.setSplitRows(false);
|
|
|
+ imageInnerTable.setSplitLate(true);
|
|
|
for (String image : imageList) {
|
|
|
Image imageData = convertFileToByteArray(new File(image));
|
|
|
if (imageData != null) {
|
|
|
- imageData.scaleAbsolute(120, 120);
|
|
|
+ imageData.scaleAbsolute(imageWith, imageHigh);
|
|
|
}
|
|
|
PdfPCell innerCell = new PdfPCell(imageData);
|
|
|
+ innerCell.setNoWrap(false);
|
|
|
+ innerCell.setPaddingTop(8f);
|
|
|
+ innerCell.setPaddingLeft(8f);
|
|
|
+ innerCell.setPaddingRight(8f);
|
|
|
+ innerCell.setPaddingBottom(8f);
|
|
|
innerCell.setBorder(Rectangle.NO_BORDER);
|
|
|
innerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
innerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
imageInnerTable.addCell(innerCell);
|
|
|
}
|
|
|
outCell.addElement(imageInnerTable);
|
|
|
+ table.setSplitRows(false);
|
|
|
+ table.setSplitLate(true);
|
|
|
table.addCell(outCell);
|
|
|
}
|
|
|
|
|
|
@@ -464,15 +467,6 @@ public class PdfUtil {
|
|
|
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
innerTable.addCell(cell);
|
|
|
}
|
|
|
- //实际上这儿永远不会存在不满足3个的情况,因为上面会根据图片数量补全到十二个
|
|
|
- //具体补全数量可以根据实际图片大小与页面尺寸来调整
|
|
|
- /* int size = row.size();
|
|
|
- while (size < 3) {
|
|
|
- PdfPCell emptyCell = new PdfPCell();
|
|
|
- emptyCell.setBorder(Rectangle.NO_BORDER);
|
|
|
- innerTable.addCell(emptyCell);
|
|
|
- size++;
|
|
|
- }*/
|
|
|
}
|
|
|
PdfPTable outerTable = new PdfPTable(1);
|
|
|
PdfPCell innerCell = new PdfPCell(innerTable);
|
|
|
@@ -509,7 +503,23 @@ public class PdfUtil {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ public static void dealAccessPBody(Document document, PdfPTable table, Font tableFont, Font tableTitleFont, List<AccessDataVo> data)throws DocumentException {
|
|
|
+ PdfUtil.createPDFCell(tableTitleFont, table, "序号", Element.ALIGN_MIDDLE, 2, 0);
|
|
|
+ PdfUtil.createPDFCell(tableTitleFont, table, "视频主机", Element.ALIGN_MIDDLE, 5, 0);
|
|
|
+ PdfUtil.createPDFCell(tableTitleFont, table, "视频通道", Element.ALIGN_MIDDLE, 5, 0);
|
|
|
+ PdfUtil.createPDFCell(tableTitleFont, table, "项目", Element.ALIGN_MIDDLE, 5, 0);
|
|
|
+ PdfUtil.createPDFCell(tableTitleFont, table, "检查情况", Element.ALIGN_MIDDLE, 2, 0);
|
|
|
+ PdfUtil.createPDFCell(tableTitleFont, table, "说明", Element.ALIGN_MIDDLE, 17, 0);
|
|
|
+ for (int i = 1; i <= data.size(); i++) {
|
|
|
+ PdfUtil.createPDFCell(tableFont, table, String.valueOf(i), Element.ALIGN_MIDDLE, 2, 0, 10);
|
|
|
+ PdfUtil.createPDFCell(tableFont, table, data.get(i - 1).getHostName(), Element.ALIGN_MIDDLE, 5, 0, 10);
|
|
|
+ PdfUtil.createPDFCell(tableFont, table, data.get(i - 1).getVideoChannelName(), Element.ALIGN_MIDDLE, 5, 0, 10);
|
|
|
+ PdfUtil.createPDFCell(tableFont, table, data.get(i - 1).getProject(), Element.ALIGN_MIDDLE, 5, 0, 10);
|
|
|
+ PdfUtil.createPDFCell(tableFont, table, data.get(i - 1).getSituation().equals("0") ? "正常" : "异常", Element.ALIGN_MIDDLE, 2, 0, 10);
|
|
|
+ PdfUtil.createPDFCell(tableFont, table, data.get(i - 1).getAbnormalIllustrate(), Element.ALIGN_MIDDLE, 17, 0, 10);
|
|
|
+ }
|
|
|
+ document.add(table);
|
|
|
+ }
|
|
|
public static void dealSafeCheckPBody(Document document, PdfPTable table, Font tableFont, Font tableTitleFont, List<CheckDataVo> data) throws DocumentException {
|
|
|
PdfUtil.createPDFCell(tableTitleFont, table, "序号", Element.ALIGN_MIDDLE, 2, 0);
|
|
|
PdfUtil.createPDFCell(tableTitleFont, table, "检查内容", Element.ALIGN_MIDDLE, 5, 0);
|