-
Notifications
You must be signed in to change notification settings - Fork 5
Format Text in Document
shoaibkhan-aspose edited this page Sep 23, 2014
·
1 revision
// Create a new document from scratch
XWPFDocument doc = new XWPFDocument();
// create paragraph
XWPFParagraph para = doc.createParagraph();
// create a run to contain the content
XWPFRun rh = para.createRun();
// Format as desired
rh.setFontSize(15);
rh.setFontFamily("Verdana");
rh.setText("This is the formatted Text");
rh.setColor("fff000");
para.setAlignment(ParagraphAlignment.RIGHT);
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set paragraph formatting properties
ParagraphFormat paragraphFormat = builder.getParagraphFormat();
paragraphFormat.setAlignment(ParagraphAlignment.CENTER);
paragraphFormat.setLeftIndent(50);
paragraphFormat.setRightIndent(50);
paragraphFormat.setSpaceAfter(25);
// Output text
builder.writeln("I'm a very nice formatted paragraph. I'm intended to demonstrate how the left and right indents affect word wrapping.");
// Set font formatting properties
Font font = builder.getFont();
font.setBold(true);
font.setColor(Color.BLUE);
font.setItalic(true);
font.setName("Arial");
font.setSize(24);
font.setSpacing(5);
font.setUnderline(Underline.DOUBLE);
// Output formatted text
builder.writeln("I'm a very nice formatted string.");
Download Source Code
Many more examples are available at Aspose Docs
For further releases and updates, please follow these new repositories:
- Aspose.Words Java for Apache POI
- Aspose.Cells Java for Apache POI
- Aspose.Slides Java for Apache POI
- Aspose.Email Java for Apache POI
- For documentation, please visit Aspose Docs.
- Raise your queries and suggest more examples via Aspose Forums or via new social coding sites.