How to get the end position of last table in the page?
Daya2006 opened this issue · comments
Hi,
I am trying to add multiple tables appended in the same page.
Because i have a requirement to display the data from multiple table and the fomat for each data is Different, some needs to be written in 2 columns (cannot do the col span because the size of column should be less in this case )and some 4 -5 columns
Is therea way I can get the StartY location from the previous table which is written in page? so that i can append the table at correct location based on that?
Hi @Daya2006,
maybe have a look here:
- #59 and the corresponding gist:
- https://gist.github.com/vandeseer/6758c76fc4070a5bddd016c4311bc359
The basic idea is to create a custom table drawer that stores this information. Since several people asked about this already I may include this feature in one of the next versions.
Hope this helps!
Stefan
Hi ,
I tried using the below code , but getting error for the annotation
@SuperBuilder
@SuperBuilder
private static class CustomTableDrawer extends TableDrawer {
@Getter
private float finalY;
@Override
protected void drawWithFunction(PageData pageData, Point2D.Float startingPoint, BiConsumer<Drawer, DrawingContext> consumer) {
super.drawWithFunction(pageData, startingPoint, consumer);
finalY = startingPoint.y;
for (int rowIndex = pageData.firstRowOnPage; rowIndex < pageData.firstRowOnNextPage; rowIndex++) {
final Row row = table.getRows().get(rowIndex);
finalY -= row.getHeight();
}
}
What error exactly did you get? You will need to include the lombok dependency:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</dependency>
thanks ..will try this out and let you know if I am able to get the desired result.
Getting Multiple errors when i use the class -
I tried copying the code mentioned in issue59 to just try it out:
but my workspace shows multiple error here as
error for below code- Implicit Super constructor TableDrawer is undefined for default constructor. Must define an explicit constructor.
@SuperBuilder
private static class CustomTableDrawer extends TableDrawer {
@Getter
private float finalY;
@Override
protected void drawWithFunction(PageData pageData, Point2D.Float startingPoint, BiConsumer<Drawer, DrawingContext> consumer) {
super.drawWithFunction(pageData, startingPoint, consumer);
finalY = startingPoint.y;
for (int rowIndex = pageData.firstRowOnPage; rowIndex < pageData.firstRowOnNextPage; rowIndex++) {
final Row row = table.getRows().get(rowIndex);
finalY -= row.getHeight();
}
}
}
error for below code- "Type Mismatch cannot convert from capture#1-of?to Issue59.CustomTableDrawer
CustomTableDrawer tableDrawer = CustomTableDrawer.builder()
.contentStream(contentStream)
.table(createHeaderTableForPage(i))
.startX(50)
.startY(document.getPage(i).getMediaBox().getHeight() - 50)
.build();
tableDrawer.draw();
Error for below code - the method getFinalY() is undefined under issue59.CustomTableDrawer
contentStream.newLineAtOffset(100, tableDrawer.getFinalY() - 12);
contentStream.showText("text after final y " + tableDrawer.getFinalY());
Hi, please have a look at:
- https://stackoverflow.com/questions/60114464/java-errors-when-i-forked-the-https-github-com-vandeseer-easytable-repository
- #60 (comment)
Long story short: Are you using Eclipse? If so, you will need to install the Lombok Plugin.
Best,
Stefan