Created
August 3, 2019 06:31
-
-
Save vandeseer/deafdad48688376ef71bf4aaec9cf23e to your computer and use it in GitHub Desktop.
Performance Test for table creation with easytable
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
@Test | |
public void perfTest2() throws IOException { | |
String outputFileName = "perfTest2.pdf"; | |
final PDDocument document = new PDDocument(); | |
RepeatedHeaderTableDrawer drawer = RepeatedHeaderTableDrawer.builder() | |
.table(create()) | |
.startX(30) | |
.startY(775F) | |
.endY(25F) // note: if not set, table is drawn over the end of the page | |
.build(); | |
do { | |
PDPage page = new PDPage(new PDRectangle(1150,800)); | |
document.addPage(page); | |
try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) { | |
drawer.contentStream(contentStream).draw(); | |
} | |
drawer.startY(page.getMediaBox().getHeight() - 50); //50 is each page height | |
} while (!drawer.isFinished()); | |
document.save(TARGET_FOLDER + "/" + outputFileName); | |
document.close(); | |
} | |
public static Table create() { | |
final Table.TableBuilder tableBuilder = Table.builder().addColumnsOfWidth(200, 200, 690); | |
for (int i=0; i<15000; i++) { | |
tableBuilder.addRow(Row.builder() | |
.add(TextCell.builder().text("Some Heading") | |
.font(PDType1Font.HELVETICA_BOLD) | |
.textColor(Color.BLACK) | |
.borderWidth(1.5F) | |
.horizontalAlignment(HorizontalAlignment.LEFT) | |
.verticalAlignment(VerticalAlignment.MIDDLE) | |
.build()) | |
.add(TextCell.builder().text("Something") | |
.textColor(Color.BLACK) | |
.borderWidth(1.5F) | |
.horizontalAlignment(HorizontalAlignment.LEFT) | |
.verticalAlignment(VerticalAlignment.MIDDLE) | |
.build()) | |
.add(TextCell.builder().text("Some title") | |
.textColor(Color.BLACK) | |
.font(PDType1Font.HELVETICA_BOLD) | |
.borderWidth(1.5F) | |
.horizontalAlignment(HorizontalAlignment.LEFT) | |
.verticalAlignment(VerticalAlignment.MIDDLE) | |
.build()) | |
.build()); | |
} | |
return tableBuilder.build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment