[英]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.