public class ParagraphAlignment
Example:
Document doc = new Document();
// A newly created blank document still comes one section, one body and one paragraph
// Calling this method will remove all those nodes to completely empty the document
doc.removeAllChildren();
// This document now has no composite nodes that content can be added to
// If we wish to edit it, we will need to repopulate its node collection,
// which we will start to do with by creating a new Section node
Section section = new Section(doc);
// Append the section to the document
doc.appendChild(section);
// Lets set some properties for the section
section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
section.getPageSetup().setPaperSize(PaperSize.LETTER);
// A section needs a body, which will contain all other nodes that can be edited
Body body = new Body(doc);
section.appendChild(body);
// The body needs to have at least one paragraph
// Note that the paragraph has not yet been added to the document, but we have to specify the parent document
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information
Paragraph para = new Paragraph(doc);
body.appendChild(para);
// We can set some formatting for the paragraph
para.getParagraphFormat().setStyleName("Heading 1");
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
// Now we can begin adding content to the document
Run run = new Run(doc);
run.setText("Hello World!");
run.getFont().setColor(Color.RED);
para.appendChild(run);
Assert.assertEquals("Hello World!" + ControlChar.SECTION_BREAK_CHAR, doc.getText());
doc.save(getArtifactsDir() + "Section.CreateFromScratch.docx");
Field Summary | ||
---|---|---|
static final int | LEFT | |
Text is aligned to the left.
|
||
static final int | CENTER | |
Text is centered horizontally.
|
||
static final int | RIGHT | |
Text is aligned to the right.
|
||
static final int | JUSTIFY | |
Text is aligned to both left and right.
|
||
static final int | DISTRIBUTED | |
Text is evenly distributed.
|
||
static final int | ARABIC_MEDIUM_KASHIDA | |
Arabic only. Kashida length for text is extended to a medium length determined by the consumer.
|
||
static final int | ARABIC_HIGH_KASHIDA | |
Arabic only. Kashida length for text is extended to its widest possible length.
|
||
static final int | ARABIC_LOW_KASHIDA | |
Arabic only. Kashida length for text is extended to a slightly longer length.
|
||
static final int | THAI_DISTRIBUTED | |
Thai only. Text is justified with an optimization for Thai.
|
public static final int LEFT
public static final int CENTER
public static final int RIGHT
public static final int JUSTIFY
public static final int DISTRIBUTED
public static final int ARABIC_MEDIUM_KASHIDA
public static final int ARABIC_HIGH_KASHIDA
public static final int ARABIC_LOW_KASHIDA
public static final int THAI_DISTRIBUTED