forked from vandeseer/easytable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinimumWorkingExample.java
62 lines (51 loc) · 2.52 KB
/
MinimumWorkingExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package org.vandeseer;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.vandeseer.easytable.TableDrawer;
import org.vandeseer.easytable.settings.BorderStyle;
import org.vandeseer.easytable.settings.HorizontalAlignment;
import org.vandeseer.easytable.structure.Row;
import org.vandeseer.easytable.structure.Table;
import org.vandeseer.easytable.structure.cell.TextCell;
import java.awt.*;
import java.io.IOException;
public class MinimumWorkingExample {
public static void main(String[] args) throws IOException {
try (PDDocument document = new PDDocument()) {
final PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
// Build the table
Table myTable = Table.builder()
.addColumnsOfWidth(200, 200)
.padding(2)
.addRow(Row.builder()
.add(TextCell.builder().text("One One").borderWidth(4).borderColorLeft(Color.MAGENTA).backgroundColor(Color.WHITE).build())
.add(TextCell.builder().text("One Two").borderWidth(0).backgroundColor(Color.YELLOW).build())
.build())
.addRow(Row.builder()
.padding(10)
.add(TextCell.builder().text("Two One").textColor(Color.RED).build())
.add(TextCell.builder().text("Two Two")
.borderWidthRight(1f)
.borderStyleRight(BorderStyle.DOTTED)
.horizontalAlignment(HorizontalAlignment.RIGHT)
.build())
.build())
.build();
// Set up the drawer
TableDrawer tableDrawer = TableDrawer.builder()
.contentStream(contentStream)
.startX(20f)
.startY(page.getMediaBox().getUpperRightY() - 20f)
.table(myTable)
.build();
// And go for it!
tableDrawer.draw();
}
document.save("example.pdf");
}
}
}