iText - Strange column- / page changing behaviour with ColumnText

后端 未结 1 1431
攒了一身酷
攒了一身酷 2021-01-21 11:45

I am quite new to iText and trying to accomplish the following:

  • read a list of text files from local hd
  • arrange the texts of the files in a 2-column layou
相关标签:
1条回答
  • 2021-01-21 12:15

    Solved! As soon as ColumnText indicates a table will not fit the current column I reinitialize ct with a new instance of ColumnText and add the table again.

    In other words: Each instance of ColumnText is exactly dealing one column of my document.

    if (ColumnText.hasMoreText(status) || mediaPoolSwitch) {
      column = Math.abs(column - 1);
      if (mediaPoolSwitch) {
          currentMediaPool = mediapool;
          column = 0;
      }
      if (column == 0) {
          document.newPage();
          writeTitle(writer.getDirectContent(), mediapool.getName());
      }
      ct = new ColumnText(writer.getDirectContent());
      ct.addElement(table);
      ct.setSimpleColumn(
          COLUMNS_COORDS[column][0], COLUMNS_COORDS[column][1],
          COLUMNS_COORDS[column][2], COLUMNS_COORDS[column][3]);
      yLine = COLUMNS_COORDS[column][3];
      LOG.debug("correcting yLine to: " + yLine);
    } else {
      ct.addElement(table);
    }
    ct.setYLine(yLine);
    ct.go();
    
    0 讨论(0)
提交回复
热议问题