我有一個包含 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 條記錄。
2 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
如何在 pdf 表中顯示另一條記錄?
首先,這也是一個你必須問自己的問題。您是否希望第 100 個條目僅填充一行三個單元格中的一個?如果是,是哪一個?還是應該跨越整行?還是您更喜歡另一種構造?
但是,我們假設您只希望第 100 個條目成為第 34 行中的第一個單元格,并且您還希望該行中的其他單元格為空。在這種情況下,有一個PdfPTable
實用方法可以用空單元格(默認單元格的副本)填充當前行:
table.completeRow();

慕容708150
TA貢獻1831條經驗 獲得超4個贊
如果(你的列表大?。ǎ?% 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 個。
}
添加回答
舉報
0/150
提交
取消