Align Paragraph at the center of the page

后端 未结 7 1357
执笔经年
执笔经年 2021-01-03 21:03

I am using itext to generate pdf file. I want to align my title in the middle of the page. Presently i am using like this

Paragraph preface = new Paragraph()         


        
7条回答
  •  北荒
    北荒 (楼主)
    2021-01-03 21:22

    I have searching solution for this to align PdfPCell text into right and also center. After modify and change the code sequence it is work.

    This code is not work to align text to center.

                  PdfPCell cell = new PdfPCell();
                  cell.addElement(new Phrase("Testing Page");
                  cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                  table.addCell(cell);
    

    After modifying code with this , it is working now.

                  Paragraph p = new Paragraph("Testing Page");
                  //Pass Paragraph object into PdfPCell 
                  PdfPCell cell = new PdfPCell(p);
                  cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                  table.addCell(cell);
    

提交回复
热议问题