我見過的處理中iText的7大表的最佳方式http://developers.itextpdf.com/examples/tables/clone-large-tables嵌套大表中itext7
解釋我裏面有另外一個表。如果大桌子是內桌子呢?
Table outTable = new Table(new float[]{1f},true);
Cell cellHeader1 = new Cell();
cellHeader1.add(new Paragraph("Header 1").addStyle(style));
outTable.addHeaderCell(cellHeader1);
document.add(outTable);
for (int i=0; i<smallArray.size();i++) {
Table innerTable = new Table(new float[]{0.5f,0.5f},true);
Cell cellHeader2 = new Cell(1,2);
cellHeader2.add(new Paragraph("Header 2").addStyle(style));
innerTable.addHeaderCell(cellHeader2);
Cell cellInnerTable = new Cell();
cellInnerTable.add(innerTable);
outTable.addCell(cellInnerTable);
for(int j=0;j<bigArray.size();j++){
//add cells to innerTable;
if (j%20==0){
innerTable.flush(); (1)
outTable.flush(); (2)
}
}
innerTable.complete(); (1)
}
outTable.complete();
(2)此刷新不能解決內存問題。 (1)這些行在Table對象的第539行中返回一個NullPointerException,因爲document爲null。 outTable的父項是文檔,因此'flush'方法將數據刷新到文檔中,但innerTable的父項是outTable,而不是文檔。有沒有辦法將innerTable刷新到outTable和outTable到文檔中?
如果我將文檔設置爲innerTable,所以我沒有得到NullPointerException: innerTable.setDocument(document);
它不會像它應該那樣運行,因爲現在innerTable被刷新到文檔中,而不是進入outTable,它確實是奇怪的事情。
非常感謝!
這是一個遺憾。謝謝! – antzo