简体   繁体   English

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

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

I'm attempting to create 2 nested tables, one with captions, and the other with values (some of them blank), like so: 我正在尝试创建2个嵌套表,一个带有标题,另一个带有值(其中一些为空白),如下所示:

所需的渲染

But it renders as follows, with the value for row 4 appearing in row 3: 但是它呈现如下,第4行的值出现在第3行:

实际渲染

suggesting row 3 was somehow skipped. 建议以某种方式跳过第3行。 What am I doing wrong? 我究竟做错了什么?

Below is the code: 下面是代码:

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;
}

If anyone can help me, I would greatly appreciate it; 如果有人可以帮助我,我将不胜感激。 this is holding up an important release. 这是一个重要的发布。

Seems the problem was that the blank values. 似乎问题在于空白值。 In other words, 换一种说法,

 new PdfPCell(new Phrase(""))

does not work. 不起作用。

But if I insert any character, such as a space: 但是,如果我插入任何字符,例如空格:

new PdfPCell(new Phrase(" "))

the problem disappears. 问题消失了。

I don't know why this happens. 我不知道为什么会这样。 I guess an empty Phrase = empty Cell = takes up no space? 我猜一个空短语=空单元格=不占用空间? In any case, it works. 无论如何,它都有效。

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

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