亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

itextpdf 表格列數

itextpdf 表格列數

萬千封印 2022-06-23 20:37:39
我有一個包含 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();


查看完整回答
反對 回復 2022-06-23
?
慕容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 個。

}


查看完整回答
反對 回復 2022-06-23
  • 2 回答
  • 0 關注
  • 259 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號