java跳出pages为空,itext生成PDF出错java.io.IOException: The document has no pages

itext生成PDF报错java.io.IOException: The document has no pages.

其他的当获取到的list不为空是,不会报错,当获取到的list为空时,直接到close然后报错。

List freelist = new ArrayList();

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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值