itext (Text - Pdf) center alignment

6.2k views Asked by At

I am using itext to generate pdf file. I want to align my text in the middle of the page. My input file looks like in the below format

We refer to the ISDA Credit Support Annex dated as of 1 Oct 2009. Below is the data.

  Portfolio MTM                                               USD 24,479,059.69
  Independent Amount                                          USD 0.00
  Threshold                                                   USD 1,000,000.00
  Credit Support Amount / Exposure                            USD 23,479,059.69

  Credit Support Balance                                      USD 26,140,600.00

  Net Margin Requirement                                      USD 2660940.31

            Minimum Transfer Amount                           USD 250,000.00
            Rounding Amount                                   USD 10,000.00

  Delivery amount                                             USD 2670000

My Java code is the below

 FileInputStream fis = new FileInputStream(inFile);
    DataInputStream in = new DataInputStream(fis);
     InputStreamReader isr=new InputStreamReader(in);
     BufferedReader br = new BufferedReader(isr);
    String strLine;
    while ((strLine = br.readLine()) != null)  {
    Paragraph para =new Paragraph(strLine+"\n");
    para.setAlignment(Element.ALIGN_JUSTIFIED);

    document.add(para);
    }

    document.close();

While trying to generate the Pdf file my alignment for the below data is not properly working. Please let me know whether the above code is correct. Thanks in Advance.

1

There are 1 answers

3
Todd On

try ALIGN_CENTER instead

Paragraph para = new Paragraph(strLine+"\n");
para.setAlignment(Element.ALIGN_CENTER);

FROM THIS ANSWER