ralfstuckert/pdfbox-layout

Columns reset index if data in them overflows current page.

Opened this issue · 7 comments

Consider having 2 columns (labels and data) if data overflows the current page it won't continue on column 2 on the next page instead it will start on column 1.

Is there a way to prevent this?

This would be the table feature which is requested by many people. Alas, currently I don't have much time to work on this.
Sorry

I have a similar problem and tried this workaround:

  • switch to column layout
  • define columns
  • write text elements of row 1 into columns
  • switch to vertical layout
  • repeat with row 2 and so on

This will ensure, that end of column 2 does not go into column 1.
Do you need some code for this workaround?

If it wouldn't cause too much trouble I'd greatly appreciate it :D.
I'm doing something similar, the thing is I never switch back to a vertical layout.

ok, I'm doing it that way:

	protected Paragraph[] pArray; 
	final String[] texts = new String[] { "", "", };
	final Alignment[] alignments = { Alignment.Left, Alignment.Right, };
	final float[] widths = { 250, 120, };
...
			texts[0] = "title";
			texts[5] = "value";
			addRow(texts, widths, alignments);
...
	protected void addRow(String[] texts, float[] widths, Alignment[] alignments) throws IOException {

		if (texts.length != alignments.length 
		 || texts.length != widths.length) {
			throw new Exception(...);
		}
		pArray = new Paragraph[texts.length];
		ColumnLayout col = new ColumnLayout(texts.length, 5);
		col.setRemoveLeadingEmptyVerticalSpace(false);
		document.add(col);
		for (int i = 0; i < texts.length; i++) {
			pArray[i] = new Paragraph();
                        pArray[i].setAlignment(alignments[i]);
                        pArray[i].setMaxWidth(widths[i]); // text can be wider than column width when maxWidth is set
			pArray[i].addMarkup(texts[i], fontsize, basefont);
			doc.add(pArray[i]);

			if (i < texts.length - 1) {
                                // no NEWCOLUMN after the last one used
				doc.add(ColumnLayout.NEWCOLUMN);
			}
		}
		doc.add(new VerticalLayout());
	}

I hope, this helps ...

Thank you!
Will have a look and see.

Yes it works and you've set me in a cleaner direction, thank you again!

No, it does not do the trick ... after a page break, the column design is ignored and text is display in the first column instead of somewhere else.
EDIT: If you want to display multiple lines, you have to put them in one paragraph and use the Paragraph extension described in Issue 63 to prevent the paragraph from being split in case of a page break.