繁体   English   中英

单列iText表中未呈现的某些行

[英]Some rows not rendered in Single column iText table

我正在尝试创建2个嵌套表,一个带有标题,另一个带有值(其中一些为空白),如下所示:

所需的渲染

但是它呈现如下,第4行的值出现在第3行:

实际渲染

建议以某种方式跳过第3行。 我究竟做错了什么?

下面是代码:

private PdfPTable getOrderHeaderTable() {
    PdfPTable table = new PdfPTable(new float[]{25f, 25f, 20f, 20f});

    table.addCell(getCaptionCell());
    table.addCell(getBillingAddressCaptionCell());
    table.addCell(getShippingAddressCaptionCell());
    addBillingAddress(table);
    addShippingAddress(table);

    // These are the nested tables I'm referring to:
    addOrderInfoCaptions(table);
    addOrderInfo(table);

    return table;
}

private void  addOrderInfoCaptions(PdfPTable table) {
    PdfPCell cell = new PdfPCell(getOrderInfoCaptionTable());
    cell.setBorder(0);
    table.addCell(cell);
}

private void addOrderInfo(PdfPTable table) {
    PdfPCell cell = new PdfPCell(getOrderInfoTable());
    cell.setBorder(0);
    table.addCell(cell);
}

private PdfPTable getOrderInfoCaptionTable() {
    PdfPTable table = new PdfPTable(1);

    table.addCell(getTextCell(bold, BaseColor.WHITE, 0, 0, "Order Date:"));
    table.addCell(getTextCell(bold, BaseColor.WHITE, 0, 0, "Order Number:"));
    table.addCell(getTextCell(bold, BaseColor.WHITE, 0, 0, "Reservation Number:"));
    table.addCell(getTextCell(bold, BaseColor.WHITE, 0, 0, "PO Number:"));
    table.addCell(getTextCell(bold, BaseColor.WHITE, 0, 0, "Gift Registry:"));

    return table;
}

private PdfPTable getOrderInfoTable() {
    PdfPTable table = new PdfPTable(1);
    table.addCell(getTextCell(regular, BaseColor.WHITE, 0, 0, getOrderDateString()));
    table.addCell(getTextCell(regular, BaseColor.WHITE, 0, 0, order.getCommerceHubId()));
    table.addCell(getTextCell(regular, BaseColor.WHITE, 0, 0, order.getReservationNumber()));
    table.addCell(getTextCell(regular, BaseColor.WHITE, 0, 0, order.getPartnerPurchaseOrderNumber()));
    table.addCell(getTextCell(regular, BaseColor.WHITE, 0, 0, getGiftRegistryID()));

    return table;
}

private String getOrderDateString() {
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    return sdf.format(order.getOrderDate());
}

protected PdfPCell getTextCell(Font font, BaseColor color, int border, int horizontalAlignment, String value) {
    PdfPCell cell = new PdfPCell(new Phrase(value, font));
    cell.setHorizontalAlignment(horizontalAlignment);
    cell.setBorder(border);
    cell.setBackgroundColor(color);
    return cell;
}

如果有人可以帮助我,我将不胜感激。 这是一个重要的发布。

似乎问题在于空白值。 换一种说法,

 new PdfPCell(new Phrase(""))

不起作用。

但是,如果我插入任何字符,例如空格:

new PdfPCell(new Phrase(" "))

问题消失了。

我不知道为什么会这样。 我猜一个空短语=空单元格=不占用空间? 无论如何,它都有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM