-
Notifications
You must be signed in to change notification settings - Fork 95
/
NestedLists.java
49 lines (38 loc) · 1.51 KB
/
NestedLists.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
package com.itextpdf.samples.sandbox.objects;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.element.ListItem;
import com.itextpdf.layout.element.Paragraph;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class NestedLists {
public static final String DEST = "./target/sandbox/objects/nested_list.pdf";
public static void main(String[] args) throws IOException {
File file = new File(DEST);
file.getParentFile().mkdirs();
new NestedLists().manipulatePdf(DEST);
}
public void manipulatePdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
List topLevel = new List();
ListItem topLevelItem = new ListItem();
topLevelItem.add(new Paragraph().add("Item 1"));
topLevel.add(topLevelItem);
List secondLevel = new List();
secondLevel.add("Sub Item 1");
ListItem secondLevelItem = new ListItem();
secondLevelItem.add(new Paragraph("Sub Item 2"));
secondLevel.add(secondLevelItem);
topLevelItem.add(secondLevel);
List thirdLevel = new List();
thirdLevel.add("Sub Sub Item 1");
thirdLevel.add("Sub Sub Item 2");
secondLevelItem.add(thirdLevel);
document.add(topLevel);
document.close();
}
}