其他的当获取到的list不为空是,不会报错,当获取到的list为空时,直接到close然后报错。
List<XfFreePO> freelist = new ArrayList<XfFreePO>();
try {
freelist = dao.getFreexfList(xvo, "0", "0");
} catch (Exception e) {
e.printStackTrace();
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
Document pdfDocument = new Document(PageSize.A4,20,20,20,20);
int submitAmount=2000;
PdfWriter writer=PdfWriter.getInstance(pdfDocument,os);
PdfHeaderFooter headerFooter = new PdfHeaderFooter();//建立模板建立页脚
writer.setBoxSize("art",PageSize.A4);
writer.setPageEvent(headerFooter);
try {
//设置中文字体和字体样式
BaseFont bfChinese1 = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font f4 = new Font(bfChinese1, 10, Font.NORMAL);
BaseFont bfChinese2 = BaseFont.createFont("C:/Windows/Fonts/Simli.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//隶书
Font f1 = new Font(bfChinese2, 18, Font.BOLD);
Font f2 = new Font(bfChinese2, 14, Font.BOLD);
Font f3 = new Font(bfChinese2, 12, Font.BOLD);
//打开PDF文件流,并建立页脚
pdfDocument.open();
//创建一个N列的表格控件
PdfPTable pdfTable = new PdfPTable(11);
float[] widths = { 0.06f, 0.06f, 0.10f, 0.20f, 0.10f, 0.08f, 0.08f, 0.08f, 0.08f, 0.08f, 0.06f};
pdfTable.setWidths(widths);
//设置表格占PDF文档100%宽度
pdfTable.setWidthPercentage(100);
//水平方向表格控件左对齐
pdfTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
//创建一个表格的表头单元格
PdfPCell Cell1 = new PdfPCell();
Cell1.setColspan(11);
Cell1.disableBorderSide(2);
Cell1.setPhrase(new Paragraph(tvo.getTabhead(), f1));
Cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
Cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
PdfPCell Cell2 = new PdfPCell();
Cell2.setColspan(11);
Cell2.disableBorderSide(1);
Cell2.disableBorderSide(2);
Cell2.setPhrase(new Paragraph("", f1));
PdfPCell Cell3 = new PdfPCell();
Cell3.setColspan(11);
Cell3.disableBorderSide(1);
Cell3.disableBorderSide(2);
Cell3.setPhrase(new Paragraph(tvo.getSt(), f2));
PdfPCell Cell4 = new PdfPCell();
Cell4.setColspan(11);
Cell4.disableBorderSide(1);
Cell4.disableBorderSide(2);
Cell4.setPhrase(new Paragraph(tvo.getEt()+" "+tvo.getCompany(),f2));
pdfTable.addCell(Cell1);
pdfTable.addCell(Cell2);