Openpdf: Nested tables

Created on 13 Aug 2018  路  7Comments  路  Source: LibrePDF/OpenPDF

Hello,

I've two issues with nested tables:

  1. above third level of nesting, the border of enclosing cell disappears;
  2. adding two nested tables to a cell, the second one has wrong size.

I attach a code snippet and current result. Code version 1.2.0.

  protected void buildPdfDocument(
      Map<String, Object> model,
      Document document,
      PdfWriter writer,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    Table subsubtable = newTable();
    subsubtable.addCell("key1");
    subsubtable.addCell("value1");
    subsubtable.addCell("key2");
    subsubtable.addCell("value2");

    Table subtable = newTable();
    subtable.addCell("key1");
    subtable.addCell("value1");
    subtable.addCell("key2");
    subtable.addCell(new Cell(subsubtable));

    Table table = newTable();
    table.addCell("key1");
    table.addCell("value1");
    table.addCell("key2");
    Cell cell = new Cell();
    cell.addElement(new Chunk("Element 1"));
    cell.addElement(subtable);
    cell.addElement(new Chunk("Element 2"));
    cell.addElement(subtable);
    table.addCell(cell);

    document.add(table);
  }

  protected Table newTable() {
    Table table = new Table(2);
    table.setWidth(95f);
    table.setPadding(2f);
    table.setWidths(new int[] {20, 80});
    return table;
  }

image

All 7 comments

Thanks for the bugreport. Pull-requests to fix this is welcome.

Do you know if this has worked correctly in a previous version? For example, OpenPDF 1.0.1, 1.0.5, iText 1.2.7, or iText 4.2.0?

Tested with all suggested version, with no luck. I think you meant iText 2.1.7, right?

Use PdfPTable and PdfPCell.

@bberto Did this solve your problem?

@bberto Please let us know if the proposed solution works.

Then please reopen this bugreport.

It works! Thanks!

Was this page helpful?
0 / 5 - 0 ratings