vandeseer / easytable

Small table drawing library built upon Apache PDFBox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weird behaviour for ParagraphCells

Thejipppp opened this issue Β· comments

Hi, firstly I would like to thank you for this great library! It is amazing!

However, I found some bugs when using the new ParagraphCells.

A first one is that text can not be underlined and strikethrough at the same time. I think the problem lies in the fact that they both have the same (ending) symbol which makes parsing really difficult.
I personally fixed this by adapting the pdf-layout library and making strikethrough another symbol ("~~"). To be fair, I just copied the functionally of underlining and when both are needed, I make sure that I use __ ~~{0.25:} or ~~ __{0.25:}, the symbols don't clash anymore and there isn't a problem anymore. I also notified PDF-Layout about this.

A second one bothers me a bit more. To get the height of a row, you have to build it (which is very logical). However, when you build a table twice with the same paragraphcells, the text is also doubled! This isn't the case for other cells, so I think this is a bug. Please, if there is a simple work around to get the height of a row, tell me ! πŸ˜‹
I cracked my head to work around this, by making a new paragraph cell but with the same paragraph, which has the same behaviour. I even went further and tried to copy a new paragraph, but the markup isn't gettable, so that was also a dead end.
The reason I needed the height was that my table behaves weird when it crosses multiple pages. I have one big cell in my first column and smaller ones in the next columns. I don't have time left to create a code example for that, but it looks like the image below, the lower right corner is not bordered. For a solution I wanted to get the height and split cells up to fit on a page.

image

The code beneath results in this table.
image

For my example, I dirty edited your test case, sorry for that πŸ˜„

private Table createParagraphTable() {
		TableBuilder table = Table.builder().addColumnsOfWidth(200, 200).borderColor(WHITE).fontSize(8)
				.font(HELVETICA_BOLD_OBLIQUE)
				.addRow(Row.builder().backgroundColor(GRAY).textColor(WHITE).horizontalAlignment(CENTER)
						.add(TextCell.builder().borderWidth(1).text("Markup").build())
						.add(TextCell.builder().borderWidth(1).text("No Markup").build()).build())
				.addRow(Row.builder().backgroundColor(LIGHT_GRAY).add(ParagraphCell.builder().borderWidth(1).padding(8)
						.lineSpacing(1.2f)
						.paragraph(Paragraph.builder().append(Markup.builder()
								.markup("Beneath is an example of __underscored__ and __{0.25:}striked through__ \n"
										+ " __ __{0.25:}text, both at the same time__ __")
								.font(Markup.MarkupSupportedFont.TIMES).build()).build())
						.build())
						.add(ParagraphCell.builder().borderWidth(1).padding(8).lineSpacing(1.2f).paragraph(Paragraph
								.builder()
								.append(StyledText
										.builder().text("This is some text in one font.").font(HELVETICA).build())
								.appendNewLine()
								.append(StyledText.builder().text(
										"But this text that introduces a link that follows is different. Here comes the link: ")
										.font(COURIER_BOLD).fontSize(6f).build())
								.append(Hyperlink.builder().text("github!").url("http://www.github.com")
										.font(COURIER_BOLD).fontSize(6f).color(WHITE).build())
								.appendNewLine(6f)
								.append(StyledText.builder().text(
										"There was the link. And now we are using the default font from the cell.")
										.build())
								.build()).build())
						.build());
		// .build();
		table.build();
		return table.build();
	}

Hey @Thejipppp,

thanks for reporting and thanks especially for providing an example for reproducing the issue.

I will have a look soon – but let me already say: Unfortunately the pdfbox-layout library won't be developed any further and this library depends on it. But well, you solved your markup issue already anyway πŸ˜‰

Secondly the whole wrapping approach is a bit experimental and a bit hacky. I simply didn't want to reinvent the wheel whilst still being able to allow for links and formatting. Personally I don't even have a use case for it, I just implemented this kind of as proof of concept since several people asked for it. So it doesn't surprise me that much that there are issues here πŸ˜„

Anyway I will have a look and see if I can come up with a solution.

Best,
Stefan

Thank you for the very quick response!

If I could help by providing an example of the weird multipage example, let me know πŸ˜ƒ
Something I noticed is that when a normal cell would span multiple pages, an error is thrown if I remember correctly, but this was not the case for the first small long cell. Anyway, have fun debugging πŸ˜„

Kind regards,
Jesper

I think I found the issue and fixed it on the develop branch. At least it seems fine for your example. Maybe you can give it a go.

Regarding your problem of getting the height of a cell: From the top of my head I think you could create another table with one column of the same width as the one in your original table and only the cell in question. After you created that table you just do a table.getHeight() which should be exactly the height of the cell.
Or like so: table.build().getRows().get(0).getCells().get(0).getHeight()

Both are quite some hacks though ... πŸ˜„

Hope this helps,
Stefan

What a nice simple fix πŸ₯°
Thank you sir for the unbelievable fast service! You are a hero!

Kind regards
Jesper

Thank you, sir! πŸ˜‰

I will release a new bugfix version soon (that will be 0.8.1).

Best,
Stefan