Некоторые строки не отображаются в таблице с одним столбцом iText - PullRequest
0 голосов
/ 20 февраля 2019

Я пытаюсь создать 2 вложенные таблицы, одну с заголовками, а другую со значениями (некоторые из них пустые), например так:

Desired rendering

Но это выглядит следующим образом: значение для строки 4 появляется в строке 3:

Actual rendering

, предполагая, что строка 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;
}

Если кто-нибудь может мне помочь, я был бы очень признателен;это задерживает важный выпуск.

1 Ответ

0 голосов
/ 20 февраля 2019

Кажется, проблема была в том, что пустые значения.Другими словами,

 new PdfPCell(new Phrase(""))

не работает.

Но если я вставлю какой-либо символ, например пробел:

new PdfPCell(new Phrase(" "))

, проблема исчезнет.

Я не знаю, почему это происходит.Я думаю, пустая фраза = пустая ячейка = не занимает места?В любом случае, это работает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...