1212import com .itextpdf .text .BaseColor ;
1313import com .itextpdf .text .Document ;
1414import com .itextpdf .text .Element ;
15+ import com .itextpdf .text .Paragraph ;
1516import com .itextpdf .text .Image ;
1617import com .itextpdf .text .Phrase ;
1718import com .itextpdf .text .pdf .PdfPCell ;
@@ -29,6 +30,13 @@ public static void main(String[] args) {
2930
3031 document .open ();
3132
33+ Document documentParagraph = new Document ();
34+ PdfWriter .getInstance (documentParagraph , new FileOutputStream ("iTextParagraph.pdf" ));
35+
36+ documentParagraph .open ();
37+
38+ addParagraphInCenter (documentParagraph );
39+
3240 PdfPTable table = new PdfPTable (3 );
3341 addTableHeader (table );
3442 setAbsoluteColumnWidths (table );
@@ -45,6 +53,12 @@ public static void main(String[] args) {
4553 }
4654 }
4755
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+
4862 private static void addTableHeader (PdfPTable table ) {
4963 Stream .of ("column header 1" , "column header 2" , "column header 3" )
5064 .forEach (columnTitle -> {
0 commit comments