我有一个包含100条记录的列表,我想用pdf制作一个包含3列的表格。我的问题是,一旦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列。
创建33行后,剩余1项添加到新列表中。
剩下的1或2列添加新行。
注意:在任何情况下,您只剩下1或2。
}