我正在使用iText 5.5.4生成pdf。分頁符中行跨越單元格中的文本
我有一堆行應該組合在一起,並有一個rowspan單元格來命名組。但是,在分頁符中,「GRP」一詞被分解爲「G」 和「RP」。有沒有辦法讓團體牢不可破,這樣如果它不適合當前的那個,它會在下一頁繪製出來?
我試過keepRowsTogether
和setBreakpoints
,但沒有得到一致的結果。
-------------------
| G | row 1 |
| R | row 2 |
| P | row 3 |
-------------------
版面圖:
Document document = new Document(new Rectangle(300, 125));
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
document.add(new Paragraph("Table with setSplitLate(true):"));
PdfPTable table = new PdfPTable(2);
table.setWidths(new float[]{1,5});
table.setSpacingBefore(10);
PdfPCell cell = new PdfPCell();
cell.addElement(new Paragraph("G"));
cell.addElement(new Paragraph("R"));
cell.addElement(new Paragraph("O"));
cell.addElement(new Paragraph("U"));
cell.addElement(new Paragraph("P"));
//PdfPCell cell = new PdfPCell(new Phrase("GROUP"));
//cell.setNoWrap(true);
//cell.setRotation(90);
//cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setRowspan(5);
table.addCell(cell);
table.addCell("row 1");
table.addCell("row 2");
table.addCell("row 3");
table.addCell("row 4");
table.addCell("row 5");
document.add(table);
document.add(new Paragraph("Table with setSplitLate(false):"));
table.setSplitLate(false);
document.add(table);
document.close();
我更新了您分享的代碼以重現我面臨的問題。評論部分是我如何實際添加文本到行跨單元。 –
如果您能夠重現代碼示例中的問題,請讓我知道。我沒有使用「setSplitLate」標誌。我想要的只是如果組名不能適合當前頁面在下一頁上繪製它。動態地從數據源中提取組的名稱和組的行號。 –
嗨,我回顧了我的代碼,我犯了一個錯誤。我分享的例子突破了,因爲它無法適應下一頁的表格。我的代碼的問題是由於多級表。外表無法完全適合一頁,因此無論內表中的數據是否適合下一頁或不。它的工作很好,一旦我刪除了外部表格,對版面進行了輕微的修改。 –