-
Notifications
You must be signed in to change notification settings - Fork 71
Vertical Layout
The vertical layout is the default used in the document. It stacks paragraphs vertically on the page.
If the remaining space on the page is not sufficient, it will ask the element whether it is dividable, so the element itself can do its best to perform pagination. If this is not the case, the cutter is used, which simply cuts the element vertically into pieces.
If an element does not need all the space available horizontally, it will be aligned using the alignment provided by the VerticalLayoutHint. By default, left alignment is used. You can see the result of using the alignment in example Aligned.java resp. aligned.pdf. The VerticalLayoutHint
class defines some constants for simple alignment without any margins. The following snippet creates a paragraph with right-aligned text, where the paragraph itself is centered horizontally on the page.
paragraph = new Paragraph();
paragraph.addText("Text is right aligned, and paragraph centered", 11,
PDType1Font.HELVETICA);
paragraph.setAlignment(Alignment.Right);
paragraph.setMaxWidth(40);
document.add(paragraph, VerticalLayoutHint.CENTER);
The VerticalLayoutHint allows you to specify left, right, top and bottom margins that will be applied to the element to layout. See example Margin.java resp. Margin.pdf. By default, the margins are 0
. The following snippet adds a paragraph right-aligned with a left and right margin of 150
, and a top margin of 20
.
paragraph = new Paragraph();
paragraph.addText(text3, 11, PDType1Font.HELVETICA);
document.add(paragraph, new VerticalLayoutHint(Alignment.Right,
150, 150, 20, 0));