|
|
@@ -29,12 +29,14 @@ import java.util.Map;
|
|
|
public class PdfUtil {
|
|
|
|
|
|
|
|
|
+ public static Document createDocument(float marginLeft, float marginRight, float marginTop, float marginBottom) {
|
|
|
+ return new Document(PageSize.A4, marginLeft, marginRight, marginTop, marginBottom);
|
|
|
+ }
|
|
|
+
|
|
|
public static ItextPdfTableVo createTable(String filename, int numColumns, int fontSize) throws Exception {
|
|
|
- Document document = new Document(PageSize.A4, 0, 0, 50, 100);//SUPPRESS
|
|
|
+ Document document = createDocument(0, 0, 50, 50);
|
|
|
File file = FileUtils.getFile(filename);
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
- String afterStr_1 = StringEscapeUtils.escapeEcmaScript(filename);
|
|
|
- log.info("filename,{}", afterStr_1);
|
|
|
final PdfWriter writer = PdfWriter.getInstance(document, fos);
|
|
|
document.open();
|
|
|
// 使用语言包字
|
|
|
@@ -278,11 +280,17 @@ public class PdfUtil {
|
|
|
createPDFCell(tableFont, table, data.get("inTime").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
createPDFCell(tableFont, table, "离开时间", Element.ALIGN_CENTER, 1, 1);
|
|
|
createPDFCell(tableFont, table, data.get("outTime").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
+
|
|
|
+ //第六行
|
|
|
+ createPDFCell(tableFont, table, "陪同人员", Element.ALIGN_CENTER, 1, 1);
|
|
|
+ createPDFCell(tableFont, table, data.get("accompanyingPerson").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
+ createPDFCell(tableFont, table, "登记人员", Element.ALIGN_CENTER, 1, 1);
|
|
|
+ createPDFCell(tableFont, table, data.get("createBy").toString(), Element.ALIGN_CENTER, 2, 1);
|
|
|
// /statics/2023/12/05/20231205183106A001.png
|
|
|
//证件图片
|
|
|
- createPDFCell(tableFont, table, "证件图片", Element.ALIGN_CENTER, 1, 70);
|
|
|
- //演练情况 图片填充
|
|
|
- final PdfPTable imageTable1 = getImage((List<String>) data.get("imageFile"), 4, 150, 130, 2);
|
|
|
+ createPDFCell(tableFont, table, "证件图片", Element.ALIGN_CENTER, 1, 60);
|
|
|
+ //证件图片 图片填充
|
|
|
+ final PdfPTable imageTable1 = getImage((List<String>) data.get("imageFile"), 2, 150, 150, 2);
|
|
|
final PdfPCell cell1 = new PdfPCell();
|
|
|
cell1.setNoWrap(false);
|
|
|
cell1.setPaddingLeft(8f);
|
|
|
@@ -290,11 +298,11 @@ public class PdfUtil {
|
|
|
cell1.setPaddingBottom(8f);
|
|
|
cell1.setPaddingTop(8f);
|
|
|
cell1.setColspan(5);
|
|
|
- cell1.setRowspan(70);
|
|
|
+ cell1.setRowspan(60);
|
|
|
//cell1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
cell1.addElement(imageTable1);
|
|
|
table.addCell(cell1);
|
|
|
- createPDFCell(tableFont, table, "介绍信附件", Element.ALIGN_CENTER, 1, 70);
|
|
|
+ createPDFCell(tableFont, table, "介绍信附件", Element.ALIGN_CENTER, 1, 60);
|
|
|
final PdfPTable imageTable2 = getImage((List<String>) data.get("file"), 2, 150, 150, 2);
|
|
|
final PdfPCell cell2 = new PdfPCell();
|
|
|
cell2.setNoWrap(false);
|
|
|
@@ -303,11 +311,11 @@ public class PdfUtil {
|
|
|
cell2.setPaddingBottom(8f);
|
|
|
cell2.setPaddingTop(8f);
|
|
|
cell2.setColspan(5);
|
|
|
- cell2.setRowspan(70);
|
|
|
+ cell2.setRowspan(60);
|
|
|
//cell1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
cell2.addElement(imageTable2);
|
|
|
table.addCell(cell2);
|
|
|
- createPDFCell(tableFont, table, "身份核验材料", Element.ALIGN_CENTER, 1, 70);
|
|
|
+ createPDFCell(tableFont, table, "身份核验材料", Element.ALIGN_CENTER, 1, 60);
|
|
|
final PdfPTable imageTable3 = getImage((List<String>) data.get("checkImage"), 2, 150, 150, 2);
|
|
|
final PdfPCell cell3 = new PdfPCell();
|
|
|
cell3.setNoWrap(false);
|
|
|
@@ -316,7 +324,7 @@ public class PdfUtil {
|
|
|
cell3.setPaddingBottom(8f);
|
|
|
cell3.setPaddingTop(8f);
|
|
|
cell3.setColspan(5);
|
|
|
- cell3.setRowspan(70);
|
|
|
+ cell3.setRowspan(60);
|
|
|
//cell1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
|
|
|
cell3.addElement(imageTable3);
|
|
|
table.addCell(cell3);
|
|
|
@@ -365,11 +373,11 @@ public class PdfUtil {
|
|
|
//一行展示一张图片
|
|
|
dealEduImageCell(new ArrayList<>(stringList), innerTable, 2, 150, 200);
|
|
|
document.newPage();
|
|
|
- document.add(innerTable);
|
|
|
- }
|
|
|
+ document.add(innerTable);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public static void dealDrillImageCell( List<String> imageList, PdfPTable table) throws Exception {
|
|
|
+ public static void dealDrillImageCell(List<String> imageList, PdfPTable table) throws Exception {
|
|
|
//签字区域
|
|
|
PdfPCell outCell = new PdfPCell();
|
|
|
outCell.setColspan(5);
|
|
|
@@ -502,7 +510,8 @@ public class PdfUtil {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
- public static void dealAccessPBody(Document document, PdfPTable table, Font tableFont, Font tableTitleFont, List<AccessDataVo> data)throws DocumentException {
|
|
|
+
|
|
|
+ public static void dealAccessPBody(Document document, PdfPTable table, Font tableFont, Font tableTitleFont, List<AccessDataVo> data) throws DocumentException {
|
|
|
|
|
|
PdfUtil.createPDFCell(tableTitleFont, table, "序号", Element.ALIGN_MIDDLE, 3, 0);
|
|
|
PdfUtil.createPDFCell(tableTitleFont, table, "硬盘录像机", Element.ALIGN_MIDDLE, 16, 0);
|
|
|
@@ -516,9 +525,10 @@ public class PdfUtil {
|
|
|
PdfUtil.createPDFCell(tableFont, table, data.get(i - 1).getProject(), Element.ALIGN_MIDDLE, 9, 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, 9, 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);
|
|
|
@@ -537,25 +547,21 @@ public class PdfUtil {
|
|
|
document.add(table);
|
|
|
}
|
|
|
|
|
|
- public static void addPageNum(String srcPdfPath, String tagetPdfPath) {
|
|
|
+ public static void addPageNum(String srcPdfPath, String targetPdfPath, BaseFont fs, Font tableFont) {
|
|
|
try {
|
|
|
// 输出文件 流
|
|
|
- FileOutputStream fos = new FileOutputStream(tagetPdfPath);
|
|
|
-
|
|
|
+ FileOutputStream fos = new FileOutputStream(targetPdfPath);
|
|
|
// 读取 源PDF文件,进行一页一页复制,才能触发 添加页码的 页面监听事件
|
|
|
PdfReader reader = new PdfReader(srcPdfPath);
|
|
|
// 获取 源文件总页数
|
|
|
int num = reader.getNumberOfPages();
|
|
|
-
|
|
|
// 新建文档,默认A4大小
|
|
|
- Document document = new Document(PageSize.A4);
|
|
|
+ Document document =createDocument(0,0,50,50);
|
|
|
PdfWriter writer = PdfWriter.getInstance(document, fos);
|
|
|
- // 设置页面监听事件,必须在open方法前
|
|
|
- // writer.setPageEvent(new PdfPageHelperEvent(num,writer,document,));
|
|
|
+ writer.setPageEvent(new PdfPageHelperEvent(num, writer, fs, tableFont));
|
|
|
document.open();
|
|
|
// PDF内容体
|
|
|
PdfContentByte pdfContent = writer.getDirectContent();
|
|
|
- //System.out.println("总页数:" + num);
|
|
|
// 页面数是从1开始的
|
|
|
for (int i = 1; i <= num; i++) {
|
|
|
document.newPage();
|
|
|
@@ -567,7 +573,9 @@ public class PdfUtil {
|
|
|
}
|
|
|
document.close();
|
|
|
reader.close();
|
|
|
- }catch (Exception e){
|
|
|
+ final File file = new File(srcPdfPath);
|
|
|
+ file.delete();
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|