[英]itextpdf table number of columns
我有100条记录的清单,我想用3列以pdf格式创建表格。 我的问题是,一旦将pdf文件制作为33行3列,那么它的记录为99,而不是100。如何在pdf表中显示另一条记录?
这是我的代码:
Document document = new Document(PageSize.A4, -60f, -60f, 18f, 5f);
PdfPTable table = new PdfPTable(3);
PdfPCell cell;
if (filterPins.size() > 0) {
for (int i = 0; i < filterPins.size(); i++) {
Bitmap bmp = getRecyclerViewScreenshot(pinList, i);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image image = Image.getInstance(stream.toByteArray());
cell = new PdfPCell(image, true);
cell.setPadding(0f);
cell.setBorder(Rectangle.NO_BORDER);
table.addCell(cell);
}
File myDirectory = new File(rootView.getContext().getFilesDir(), String.valueOf(factorNo));
if (!myDirectory.exists()) {
myDirectory.mkdirs();
}
File pdfFile = new File(myDirectory, fileName);
PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
document.open();
document.add(table);
document.close();
}
filterPins是我的arrayList,包含100条记录。
如何在pdf表中显示另一条记录?
首先,这也是您必须问自己的问题。 您是否希望第100个条目仅填充一行三个单元格中的一个? 如果是,是哪一个? 还是应该跨越整个行? 还是您想要其他结构?
但是,假设您只是希望第100个条目成为第34行的第一个单元格,并且还希望该行中的其他单元格为空。 在那种情况下,有一个PdfPTable
实用程序方法用空单元格(默认单元格的副本)填充当前行:
table.completeRow();
if(yourlist.size()%3 == 0){
int totalRows = yourlist.size()/ 3;
创建您的pdf。
例如list.size()= 99,则创建33行,每行有3列。
}
其他{
int totalRows = yourlist.size()/ 3;
例如,如果yourlist.size()= 100。
然后先创建33行,每行有3列。
剩余的1项在创建33行后添加到新列表中。
剩下的1或2列添加到新行中。
注意:无论如何,您只剩下1或2。
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.