|
|
@@ -1,6 +1,7 @@
|
|
|
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.*;
|
|
|
@@ -144,6 +145,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 +171,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(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);
|
|
|
@@ -410,8 +424,10 @@ public class PdfUtil {
|
|
|
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");
|
|
|
+ if (imageAddNums != 0) {
|
|
|
+ for (int i = 0; i < 3 - imageAddNums; i++) {
|
|
|
+ imageList.add("black.png");
|
|
|
+ }
|
|
|
}
|
|
|
PdfPTable imageInnerTable = new PdfPTable(3);
|
|
|
for (String image : imageList) {
|
|
|
@@ -429,6 +445,43 @@ public class PdfUtil {
|
|
|
table.addCell(outCell);
|
|
|
}
|
|
|
|
|
|
+ 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);
|
|
|
+ // 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(imageNumsOfRow);
|
|
|
+ imageInnerTable.setSplitRows(false);
|
|
|
+ imageInnerTable.setSplitLate(true);
|
|
|
+ for (String image : imageList) {
|
|
|
+ Image imageData = convertFileToByteArray(new File(image));
|
|
|
+ if (imageData != null) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private static PdfPTable getImage(List<String> images, int totalImages, float imageWidth, float imageHeight, Integer ImageNumsOfRow) throws Exception {
|
|
|
if (images == null) {
|
|
|
@@ -464,15 +517,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);
|