| | |
| | | return font; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("设置字体失败!"); |
| | | throw new RuntimeException("设置字体失败!"+FONT_PATH); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public static PdfPTable setTable2(Font headFont, Font textFont, String[] title, List<TjPdfVO> list,boolean flag) { |
| | | public static PdfPTable setTable2(Font headFont, Font textFont, String[] title, List<TjPdfVO> list,boolean flag,float[] titleWidth) { |
| | | //四列 |
| | | PdfPTable table = createTable(new float[]{240, 240,240}); |
| | | PdfPTable table = createTable(titleWidth); |
| | | // PdfPTable table = createTable(new float[]{240, 240,240}); |
| | | //画标题 |
| | | for (String head : title) { |
| | | table.addCell(createCell(head, headFont)); |
| | |
| | | } |
| | | |
| | | |
| | | private static PdfPTable createTable(float[] widths) { |
| | | public static PdfPTable createTable(float[] widths) { |
| | | PdfPTable table = new PdfPTable(widths); |
| | | try { |
| | | // 设置表格大小 |
| | |
| | | return table; |
| | | } |
| | | |
| | | private static PdfPCell createCell(String value, Font font) { |
| | | public static PdfPCell createCell(String value, Font font) { |
| | | PdfPCell cell = new PdfPCell(); |
| | | // 水平、垂直居中 |
| | | cell.setVerticalAlignment(Element.ALIGN_MIDDLE); |
| | |
| | | |
| | | return cell; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param value |
| | | * @param font |
| | | * @param boder Rectangle类的枚举 |
| | | * @param txtAlign Element类的枚举 |
| | | * @return |
| | | */ |
| | | public static PdfPCell createCell(String value, Font font,int boder,int txtAlign,Float paddingTop,Float paddingBottom) { |
| | | PdfPCell cell = new PdfPCell(); |
| | | // 水平、垂直居中 |
| | | cell.setVerticalAlignment(Element.ALIGN_MIDDLE); |
| | | cell.setHorizontalAlignment(txtAlign); |
| | | cell.setPhrase(new Phrase(value, font)); |
| | | if (paddingTop != null) |
| | | cell.setPaddingTop(paddingTop); |
| | | if (paddingBottom != null) |
| | | cell.setPaddingBottom(paddingBottom); |
| | | // 设置无边框 |
| | | cell.setBorder(boder); |
| | | // 设置高度 |
| | | //cell.setFixedHeight(20); |
| | | |
| | | return cell; |
| | | } |
| | | } |