|
@@ -46,6 +46,32 @@ public class PdfUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static ItextPdfTableVo createTable(String filename, int numColumns, int fontSize) throws Exception {
|
|
public static ItextPdfTableVo createTable(String filename, int numColumns, int fontSize) throws Exception {
|
|
|
|
|
+ Document document = createDocument(0, 0, 50, 50);
|
|
|
|
|
+ File file = FileUtils.getFile(filename);
|
|
|
|
|
+ FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
|
+ final PdfWriter writer = PdfWriter.getInstance(document, fos);
|
|
|
|
|
+ document.open();
|
|
|
|
|
+ // 使用语言包字
|
|
|
|
|
+ BaseFont abf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
|
|
|
|
+ // 外部字体
|
|
|
|
|
+ BaseFont fs = BaseFont.createFont("/fonts/msyh.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
|
|
|
|
|
+ Font tableFont = new Font(fs, fontSize, Font.NORMAL);
|
|
|
|
|
+ PdfPTable table = new PdfPTable(numColumns);
|
|
|
|
|
+ // 设置各列列宽
|
|
|
|
|
+ // table.setTotalWidth(new float[]{90, 100, 100, 120, 100, 100});
|
|
|
|
|
+ table.setSpacingBefore(16f);
|
|
|
|
|
+ table.setSplitRows(true);
|
|
|
|
|
+ table.setSplitLate(false);
|
|
|
|
|
+ ItextPdfTableVo itextPdfTableVo = new ItextPdfTableVo();
|
|
|
|
|
+ itextPdfTableVo.setDocument(document);
|
|
|
|
|
+ itextPdfTableVo.setWriter(writer);
|
|
|
|
|
+ itextPdfTableVo.setAbf(abf);
|
|
|
|
|
+ itextPdfTableVo.setFs(fs);
|
|
|
|
|
+ itextPdfTableVo.setTableFont(tableFont);
|
|
|
|
|
+ itextPdfTableVo.setTable(table);
|
|
|
|
|
+ return itextPdfTableVo;
|
|
|
|
|
+ }
|
|
|
|
|
+ public static ItextPdfTableVo createOutInTable(String filename, int numColumns, int fontSize) throws Exception {
|
|
|
Document document = createDocument(0, 0, 50, 12);
|
|
Document document = createDocument(0, 0, 50, 12);
|
|
|
File file = FileUtils.getFile(filename);
|
|
File file = FileUtils.getFile(filename);
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
@@ -191,10 +217,10 @@ public class PdfUtil {
|
|
|
if (rowspan != null && rowspan > 0) {
|
|
if (rowspan != null && rowspan > 0) {
|
|
|
cell.setRowspan(rowspan);
|
|
cell.setRowspan(rowspan);
|
|
|
}
|
|
}
|
|
|
-// cell.setPaddingTop(8f);
|
|
|
|
|
|
|
+ // cell.setPaddingTop(8f);
|
|
|
cell.setPaddingLeft(paddingLeft);
|
|
cell.setPaddingLeft(paddingLeft);
|
|
|
cell.setPaddingRight(paddingRight);
|
|
cell.setPaddingRight(paddingRight);
|
|
|
-// cell.setPaddingBottom(8f);
|
|
|
|
|
|
|
+ cell.setPaddingBottom(8f);
|
|
|
cell.setLeading(1F, 1.5F);
|
|
cell.setLeading(1F, 1.5F);
|
|
|
if (PdfPCell.ALIGN_MIDDLE != align) {
|
|
if (PdfPCell.ALIGN_MIDDLE != align) {
|
|
|
cell.setHorizontalAlignment(align);
|
|
cell.setHorizontalAlignment(align);
|
|
@@ -354,7 +380,7 @@ public class PdfUtil {
|
|
|
//序号
|
|
//序号
|
|
|
PdfUtil.createPDFCell(tableFont, table, String.valueOf(o), PdfPCell.ALIGN_MIDDLE, 2, 0);
|
|
PdfUtil.createPDFCell(tableFont, table, String.valueOf(o), PdfPCell.ALIGN_MIDDLE, 2, 0);
|
|
|
// 检查内容
|
|
// 检查内容
|
|
|
- String rowContent = listVo.get("pointName") + "";
|
|
|
|
|
|
|
+ String rowContent = listVo.get("pointName")+"";
|
|
|
PdfUtil.createPDFCell(tableFont, table, rowContent, Element.ALIGN_LEFT, 6, 0);
|
|
PdfUtil.createPDFCell(tableFont, table, rowContent, Element.ALIGN_LEFT, 6, 0);
|
|
|
// 检查情况
|
|
// 检查情况
|
|
|
PdfUtil.createPDFCell(tableFont, table, ObjectUtil.isEmpty(listVo.get("resValue")) ? "" : (((Integer) listVo.get("resValue")) == 0 ? "正常" : "异常"), Element.ALIGN_MIDDLE, 2, 0);
|
|
PdfUtil.createPDFCell(tableFont, table, ObjectUtil.isEmpty(listVo.get("resValue")) ? "" : (((Integer) listVo.get("resValue")) == 0 ? "正常" : "异常"), Element.ALIGN_MIDDLE, 2, 0);
|