itext 导出pdf报异常。。。。。。。。。。。。。。。。。。。。。。。。。。。。
报如下异常,table宽度必须大于0?我已经设置宽度了啊,还是报错。。
用的是itext5.1.3版本,包的下载地址 --> http://sourceforge.net/projects/itext/files/iText/iText5.1.3/
Exception in thread "main"
java.lang.RuntimeException: The table width must be greater than zero.
at com.itextpdf.text.pdf.PdfPTable.writeSelectedRows(PdfPTable.java:690)
at com.itextpdf.text.pdf.PdfPTable.writeSelectedRows(PdfPTable.java:824)
at com.itextpdf.text.pdf.PdfPTable.writeSelectedRows(PdfPTable.java:772)
at com.itextpdf.text.pdf.PdfPTable.writeSelectedRows(PdfPTable.java:750)
at test.test.test2(test.java:45)
at test.test.main(test.java:20)
Java code
Document doc = new Document(PageSize.A4,10,10,10,10);
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("f:/a.pdf"));
PdfPTable table = new PdfPTable(3);
for(int i = 0;i < 9;i++)
{
PdfPCell cell = new PdfPCell();
cell.addElement(new Chunk("fff"));
table.addCell(cell);
}
doc.open();
doc.add(new Chunk("xx"));
table.setWidths(new float[]{100});
table.writeSelectedRows(1, 1, 50, 50, writer.getDirectContent());
doc.close();
------解决方案--------------------
没用过,关注中