12
12
import com .itextpdf .text .BaseColor ;
13
13
import com .itextpdf .text .Document ;
14
14
import com .itextpdf .text .Element ;
15
+ import com .itextpdf .text .Paragraph ;
15
16
import com .itextpdf .text .Image ;
16
17
import com .itextpdf .text .Phrase ;
17
18
import com .itextpdf .text .pdf .PdfPCell ;
@@ -29,6 +30,13 @@ public static void main(String[] args) {
29
30
30
31
document .open ();
31
32
33
+ Document documentParagraph = new Document ();
34
+ PdfWriter .getInstance (documentParagraph , new FileOutputStream ("iTextParagraph.pdf" ));
35
+
36
+ documentParagraph .open ();
37
+
38
+ addParagraphInCenter (documentParagraph );
39
+
32
40
PdfPTable table = new PdfPTable (3 );
33
41
addTableHeader (table );
34
42
setAbsoluteColumnWidths (table );
@@ -45,6 +53,12 @@ public static void main(String[] args) {
45
53
}
46
54
}
47
55
56
+ private static void addParagraphInCenter (Document document ) throws IOException , DocumentException {
57
+ Paragraph paragraph = new Paragraph ("This paragraph will be horizontally centered." );
58
+ paragraph .setAlignment (Element .ALIGN_CENTER );
59
+ document .add (paragraph );
60
+ }
61
+
48
62
private static void addTableHeader (PdfPTable table ) {
49
63
Stream .of ("column header 1" , "column header 2" , "column header 3" )
50
64
.forEach (columnTitle -> {
0 commit comments