Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JODF
>
Tutorial
> Set paragraph alignment
The following example shows you how to set paragraph text alignment.
import com.independentsoft.office.odf.Paragraph; import com.independentsoft.office.odf.TextDocument; import com.independentsoft.office.odf.styles.ParagraphStyle; import com.independentsoft.office.odf.styles.TextAlignment; public class Example { public static void main(String[] args) { try { TextDocument doc = new TextDocument(); ParagraphStyle style1 = new ParagraphStyle("Style1"); style1.getParagraphProperties().setTextAlignment(TextAlignment.CENTER); ParagraphStyle style2 = new ParagraphStyle("Style2"); style2.getParagraphProperties().setTextAlignment(TextAlignment.LEFT); ParagraphStyle style3 = new ParagraphStyle("Style3"); style3.getParagraphProperties().setTextAlignment(TextAlignment.RIGHT); doc.getAutomaticStyles().getStyles().add(style1); doc.getAutomaticStyles().getStyles().add(style2); doc.getAutomaticStyles().getStyles().add(style3); Paragraph p1 = new Paragraph(); p1.add("Center alignment"); p1.setStyle("Style1"); Paragraph p2 = new Paragraph(); p2.add("Left alignment"); p2.setStyle("Style2"); Paragraph p3 = new Paragraph(); p3.add("Right alignment"); p3.setStyle("Style3"); doc.getBody().add(p1); doc.getBody().add(new Paragraph()); //empty paragraph doc.getBody().add(p2); doc.getBody().add(new Paragraph()); //empty paragraph doc.getBody().add(p3); doc.save("c:\\test\\output.odt"); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*