iText 7 (Java) 当 Large Table 扩展到下一页时,它不绘制底部边框
iText 7 (Java) When Large Table extend to next page it does not draw bottom border
在我使用 iText 7 生成报告 java 的应用程序中,我需要从可能扩展到多个页面的大数据 table 中获取数据。
我的代码段生成了table。
Table table = new Table(new float[] {0.4f, 1f, 1f, 1f, 1.3f, 1f, 1.3f, 0.6f,0.6f,1.2f}, true)
.setWidth(UnitValue.createPercentValue(100))
.setMarginTop(tblTopMargin)
.setMarginBottom(0);
int count = 0;
while (!dataList.empty()) {
String[] dataRow = dataList.poll();
createDataRow(dataRow, table);
count++;
if(count % 10 == 0) {
table.flush();
}
}
下面提到createDataRaw
方法的实现,
private void createDataRow(String[] a, Table table) {
for (String s : a) {
Paragraph content = new Paragraph(s)
.setFontSize(7)
.setFixedLeading(9)
.setFontColor(new DeviceCmyk(0, 0, 0, 100));
Cell cell = new Cell()
.setBorder(new SolidBorder(ColorConstants.BLACK, 0.5f))
.setPaddingLeft(2)
.setPaddingTop(0)
.setPaddingBottom(0)
.setHorizontalAlignment(HorizontalAlignment.LEFT)
.setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(content);
table.addCell(cell);
}
}
用给定的代码table生成所有数据。但是当 tables 之间有分页符时,table 的底线不会显示,除了最后一个 table 底部。
此处附上屏幕截图,以获得更清晰的思路。
有人可以帮我解决这个问题吗?
以下代码为我的最新 7.1.16
版本的 iText 生成了我想要的结果:
Table table = new Table(new float[] {0.4f, 1f, 1f}, true)
.setWidth(UnitValue.createPercentValue(100))
.setMarginBottom(0);
document.add(table);
int count = 0;
for (int i = 0; i < 300; i++) {
String[] dataRow = new String[] {"1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "2\n3\nsf\n43", "3\nr\nsdfsd\n43"};
createDataRow(dataRow, table);
count++;
if (count % 10 == 0) {
table.flush();
}
}
table.complete();
document.close();
private void createDataRow(String[] a, Table table) {
for (String s : a) {
Paragraph content = new Paragraph(s)
.setFontSize(7)
.setFixedLeading(9)
.setFontColor(new DeviceCmyk(0, 0, 0, 100));
Cell cell = new Cell()
.setBorder(new SolidBorder(ColorConstants.BLACK, 0.5f))
.setPaddingLeft(2)
.setPaddingTop(0)
.setPaddingBottom(0)
.setHorizontalAlignment(HorizontalAlignment.LEFT)
.setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(content);
table.addCell(cell);
}
}
视觉结果(第一页结束):
在我使用 iText 7 生成报告 java 的应用程序中,我需要从可能扩展到多个页面的大数据 table 中获取数据。
我的代码段生成了table。
Table table = new Table(new float[] {0.4f, 1f, 1f, 1f, 1.3f, 1f, 1.3f, 0.6f,0.6f,1.2f}, true)
.setWidth(UnitValue.createPercentValue(100))
.setMarginTop(tblTopMargin)
.setMarginBottom(0);
int count = 0;
while (!dataList.empty()) {
String[] dataRow = dataList.poll();
createDataRow(dataRow, table);
count++;
if(count % 10 == 0) {
table.flush();
}
}
下面提到createDataRaw
方法的实现,
private void createDataRow(String[] a, Table table) {
for (String s : a) {
Paragraph content = new Paragraph(s)
.setFontSize(7)
.setFixedLeading(9)
.setFontColor(new DeviceCmyk(0, 0, 0, 100));
Cell cell = new Cell()
.setBorder(new SolidBorder(ColorConstants.BLACK, 0.5f))
.setPaddingLeft(2)
.setPaddingTop(0)
.setPaddingBottom(0)
.setHorizontalAlignment(HorizontalAlignment.LEFT)
.setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(content);
table.addCell(cell);
}
}
用给定的代码table生成所有数据。但是当 tables 之间有分页符时,table 的底线不会显示,除了最后一个 table 底部。
此处附上屏幕截图,以获得更清晰的思路。
有人可以帮我解决这个问题吗?
以下代码为我的最新 7.1.16
版本的 iText 生成了我想要的结果:
Table table = new Table(new float[] {0.4f, 1f, 1f}, true)
.setWidth(UnitValue.createPercentValue(100))
.setMarginBottom(0);
document.add(table);
int count = 0;
for (int i = 0; i < 300; i++) {
String[] dataRow = new String[] {"1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "2\n3\nsf\n43", "3\nr\nsdfsd\n43"};
createDataRow(dataRow, table);
count++;
if (count % 10 == 0) {
table.flush();
}
}
table.complete();
document.close();
private void createDataRow(String[] a, Table table) {
for (String s : a) {
Paragraph content = new Paragraph(s)
.setFontSize(7)
.setFixedLeading(9)
.setFontColor(new DeviceCmyk(0, 0, 0, 100));
Cell cell = new Cell()
.setBorder(new SolidBorder(ColorConstants.BLACK, 0.5f))
.setPaddingLeft(2)
.setPaddingTop(0)
.setPaddingBottom(0)
.setHorizontalAlignment(HorizontalAlignment.LEFT)
.setVerticalAlignment(VerticalAlignment.MIDDLE)
.add(content);
table.addCell(cell);
}
}
视觉结果(第一页结束):