vandeseer / easytable

Small table drawing library built upon Apache PDFBox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

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:

Long story short: Are you using Eclipse? If so, you will need to install the Lombok Plugin.

Best,
Stefan

Did it work in the end @Daya2006 ?
If so, please close this issue.

Thanks