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.
1 Select the text you want to center between the top and bottom margins. 2 On the Page Layout tab, click the Page Setup Dialog Box Launcher. 3 Select the Layout tab. 4 In the Vertical alignment box, click Center 5 In the Apply to box, click Selected text, and then click OK.
To set text alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property text-align for the center, left and right alignment.
How To Center Your Website. Use a container element and set a specific max-width . A common width many websites use is 960px. To actually center the page, add margin: auto .
Use Paragraph#setAlignment(int)
:
Paragraph preface = new Paragraph();
preface.setAlignment(Element.ALIGN_CENTER);
See the ALIGN_*
constants in the Element
interface for more possible values.
Not sure if this is an old version, but for PdfWriter these methods weren't there. Instead I used:
Paragraph p = new Paragraph("This too shall pass");
p.Alignment = Element.ALIGN_CENTER;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With