|
|
@@ -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();
|
|
|
// 使用语言包字
|
|
|
@@ -372,11 +374,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);
|
|
|
@@ -509,7 +511,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);
|
|
|
@@ -523,9 +526,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);
|
|
|
@@ -544,25 +548,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();
|
|
|
@@ -574,7 +574,9 @@ public class PdfUtil {
|
|
|
}
|
|
|
document.close();
|
|
|
reader.close();
|
|
|
- }catch (Exception e){
|
|
|
+ final File file = new File(srcPdfPath);
|
|
|
+ file.delete();
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|