PSR PSR - 2 years ago 174
Java Question

Align Paragraph at the center of the page

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();
for (int i = 0; i < 10; i++) {
preface.add(new Paragraph(" "));

Is it correct or is there any another best way to do this.

Answer Source

Use Paragraph#setAlignment(int) :

Paragraph preface = new Paragraph(); 

See the ALIGN_* constants in the Element interface for more possible values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download