我有一个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条记录。
发布于 2019-02-19 10:48:27
如何在pdf表格中显示另一条记录?
首先,这也是一个你必须问自己的问题。是否希望第100项只填充一行三个单元格中的一个单元格?如果是,是哪一个?还是应该跨越整排?还是你更喜欢另一种构造?
不过,让我们假设,您只是希望第100项成为第34行中的第一个单元格,并且还希望该行中的其他单元格为空。在这种情况下,有一个PdfPTable实用程序方法,它用空单元格(默认单元格的副本)填充当前行:
table.completeRow();发布于 2019-02-19 08:00:11
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。
}
https://stackoverflow.com/questions/54761145
复制相似问题