Created
February 26, 2020 21:34
-
-
Save vandeseer/8c2ca07265dc44873eeb5ead64b37dd7 to your computer and use it in GitHub Desktop.
Customized RepeatedHeaderTableDrawer with configurable amount of rows to repeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.vandeseer.integrationtest.custom; | |
import lombok.experimental.SuperBuilder; | |
import org.apache.pdfbox.pdmodel.PDDocument; | |
import org.apache.pdfbox.pdmodel.PDPage; | |
import org.vandeseer.easytable.TableDrawer; | |
import java.awt.geom.Point2D; | |
import java.io.IOException; | |
import java.util.function.Supplier; | |
@SuperBuilder | |
public class CustomRepeatedHeaderTableDrawer extends TableDrawer { | |
@Override | |
protected void drawPage(PageData pageData) { | |
if (pageData.firstRowOnPage != 0) { | |
float adaption = 0; | |
for (int i = 0; i < 3; i++) { | |
adaption += table.getRows().get(i).getHeight(); | |
drawRow(new Point2D.Float(this.startX, this.startY + calculateHeightForFirstRows(3) - adaption), table.getRows().get(i), i, (drawer, drawingContext) -> { | |
drawer.drawBackground(drawingContext); | |
drawer.drawContent(drawingContext); | |
drawer.drawBorders(drawingContext); | |
}); | |
} | |
} | |
drawerList.forEach(drawer -> | |
drawWithFunction(pageData, new Point2D.Float(this.startX, this.startY), drawer) | |
); | |
} | |
@Override | |
public void draw(Supplier<PDDocument> documentSupplier, Supplier<PDPage> pageSupplier, float yOffset) throws IOException { | |
super.draw(documentSupplier, pageSupplier, yOffset + calculateHeightForFirstRows(3)); | |
} | |
private float calculateHeightForFirstRows(int x) { | |
float height = 0; | |
for (int i = 0; i < x; i++) { | |
height += table.getRows().get(i).getHeight(); | |
} | |
return height; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for solution.