简体   繁体   中英

itext (Text - Pdf) center alignment

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.

try ALIGN_CENTER instead

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

FROM THIS ANSWER

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM