【问题标题】:Splitting rows of Nested Table OR Inner Table using iTextPDF使用 iTextPDF 拆分嵌套表或内表的行
【发布时间】:2018-07-13 19:02:12
【问题描述】:
如何拆分内表的行。根据图片描述问题。
- 在这里,我有一个名为 PARENT_TABLE 的表,它的单元格包含两个名为 HEADER_TABLE 和 的表>CONTENT_TABLE
-
CONTENT_TABLE 有一个包含 INNER_TABLE 的单元格。 INNER_TABLE 包含动态行/内容,其高度将根据内容进行更改。
所以,如果我使用一页制作这张表格,它就可以完美运行。但是如果我需要将表格拆分到不同的页面中,它会显示像 image_2 这样的错误。请帮帮我。 结果:即使页面分成两页或多页,表格也应该像 image_1 中的那样。
请查看提到的图片更清楚。
image_1
尝试从空对象引用上的“float com.itextpdf.text.pdf.ColumnText.maxY”字段读取
image_2
【问题讨论】:
标签:
java
android
pdf
itext
pdf-generation
【解决方案1】:
我刚刚找到了解决方案。仅在尝试将 PDFPTable 拆分为两页时才会出现此问题。我使用了 tableCell.setRowspan(2),所以在尝试拆分表格时会出现上述问题。
已解决:我只是创建了一个空单元格来代替使用 tableCell.setRowspan(2)。
private PdfPTable contentWithDateTitleAndDescription(String stringData1, String stringData2, String stringData3, String stringData4) throws IOException, BadElementException {
float relativeWidth[] = {2, 7};
PdfPTable table = new PdfPTable(relativeWidth);
table.setWidthPercentage(100);
PdfPCell cellA = new PdfPCell();
cellA.setBorder(Rectangle.NO_BORDER);
// dateCell.setRowspan(2);
cellA.setPaddingLeft(15);
cellA.setVerticalAlignment(Element.ALIGN_CENTER);
cellA.setPaddingTop(7);
Paragraph dateParagraph = new Paragraph(stringData1);
cellA.addElement(dateParagraph);
PdfPCell emptyCellB = new PdfPCell();
emptyCellB.setBorder(Rectangle.NO_BORDER);
PdfPCell cellC = new PdfPCell();
cellC.setBorder(Rectangle.NO_BORDER);
cellC.setVerticalAlignment(Element.ALIGN_LEFT);
Paragraph titleParagraph = new Paragraph(stringData2 + " / " + stringData3);
cellC.addElement(titleParagraph);
PdfPCell cellD = new PdfPCell();
cellD.setBorder(Rectangle.NO_BORDER);
cellD.setVerticalAlignment(Element.ALIGN_LEFT);
Paragraph descriptionParagraph = new Paragraph(stringData4);
cellD.addElement(descriptionParagraph);
cellD.setPaddingBottom(15);
table.addCell(cellA);
table.addCell(cellC);
table.addCell(emptyCellB);
table.addCell(cellD);
return table;
}