com.aspose.words

Class TextBox

  • java.lang.Object
    • com.aspose.words.TextBox
public class TextBox 
extends java.lang.Object

Defines attributes that specify how a text is displayed inside a shape.

Use the Shape.TextBox property to access text properties of a shape. You do not create instances of the TextBox class directly.

Example:

Shows how to insert text boxes and arrange their text.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a shape that contains a TextBox
Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
TextBox textBox = textBoxShape.getTextBox();

// Move the document builder to inside the TextBox and write text
builder.moveTo(textBoxShape.getLastParagraph());
builder.write("Vertical text");

// Text is displayed vertically, written top to bottom
textBox.setLayoutFlow(LayoutFlow.TOP_TO_BOTTOM_IDEOGRAPHIC);

// Move the builder out of the shape and back into the main document body
builder.moveTo(textBoxShape.getParentParagraph());

// Insert another TextBox
textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
textBox = textBoxShape.getTextBox();

// Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
textBox.setFitShapeToText(true);
textBox.setTextBoxWrapMode(TextBoxWrapMode.NONE);

builder.moveTo(textBoxShape.getLastParagraph());
builder.write("Text fit tightly inside textbox");

builder.moveTo(textBoxShape.getParentParagraph());

textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 100.0);
textBox = textBoxShape.getTextBox();

// Set margins for the textbox
textBox.setInternalMarginTop(15.0);
textBox.setInternalMarginBottom(15.0);
textBox.setInternalMarginLeft(15.0);
textBox.setInternalMarginRight(15.0);

builder.moveTo(textBoxShape.getLastParagraph());
builder.write("Text placed according to textbox margins");

doc.save(getArtifactsDir() + "Drawing.TextBox.docx");
See Also:
Shape.TextBox

Property Getters/Setters Summary
booleangetFitShapeToText()
void
setFitShapeToText(booleanvalue)
           Determines whether Microsoft Word will grow the shape to fit text.
doublegetInternalMarginBottom()
void
           Specifies the inner bottom margin in points for a shape.
doublegetInternalMarginLeft()
void
           Specifies the inner left margin in points for a shape.
doublegetInternalMarginRight()
void
           Specifies the inner right margin in points for a shape.
doublegetInternalMarginTop()
void
           Specifies the inner top margin in points for a shape.
intgetLayoutFlow()
void
setLayoutFlow(intvalue)
           Determines the flow of the text layout in a shape. The value of the property is LayoutFlow integer constant.
TextBoxgetNext()
void
           Returns or sets a TextBox that represents the next TextBox in a sequence of shapes.
ShapegetParent()
Gets a parent shape for the TextBox.
TextBoxgetPrevious()
Returns a TextBox that represents the previous TextBox in a sequence of shapes.
intgetTextBoxWrapMode()
void
           Determines how text wraps inside a shape. The value of the property is TextBoxWrapMode integer constant.
intgetVerticalAnchor()
void
           Specifies the vertical alignment of the text within a shape. The value of the property is TextBoxAnchor integer constant.
 
Method Summary
voidbreakForwardLink()
Breaks the link to the next TextBox.
booleanisValidLinkTarget(TextBox target)
Determines whether this TextBox can be linked to the target Textbox.
 

    • Property Getters/Setters Detail

      • getFitShapeToText/setFitShapeToText

        public boolean getFitShapeToText() / public void setFitShapeToText(boolean value)
        
        Determines whether Microsoft Word will grow the shape to fit text.

        The default value is false.

        Example:

        Shows how to insert text boxes and arrange their text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a shape that contains a TextBox
        Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        TextBox textBox = textBoxShape.getTextBox();
        
        // Move the document builder to inside the TextBox and write text
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Vertical text");
        
        // Text is displayed vertically, written top to bottom
        textBox.setLayoutFlow(LayoutFlow.TOP_TO_BOTTOM_IDEOGRAPHIC);
        
        // Move the builder out of the shape and back into the main document body
        builder.moveTo(textBoxShape.getParentParagraph());
        
        // Insert another TextBox
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
        textBox.setFitShapeToText(true);
        textBox.setTextBoxWrapMode(TextBoxWrapMode.NONE);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text fit tightly inside textbox");
        
        builder.moveTo(textBoxShape.getParentParagraph());
        
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Set margins for the textbox
        textBox.setInternalMarginTop(15.0);
        textBox.setInternalMarginBottom(15.0);
        textBox.setInternalMarginLeft(15.0);
        textBox.setInternalMarginRight(15.0);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text placed according to textbox margins");
        
        doc.save(getArtifactsDir() + "Drawing.TextBox.docx");
      • getInternalMarginBottom/setInternalMarginBottom

        public double getInternalMarginBottom() / public void setInternalMarginBottom(double value)
        
        Specifies the inner bottom margin in points for a shape.

        The default value is 1/20 inch.

        Example:

        Shows how to insert text boxes and arrange their text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a shape that contains a TextBox
        Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        TextBox textBox = textBoxShape.getTextBox();
        
        // Move the document builder to inside the TextBox and write text
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Vertical text");
        
        // Text is displayed vertically, written top to bottom
        textBox.setLayoutFlow(LayoutFlow.TOP_TO_BOTTOM_IDEOGRAPHIC);
        
        // Move the builder out of the shape and back into the main document body
        builder.moveTo(textBoxShape.getParentParagraph());
        
        // Insert another TextBox
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
        textBox.setFitShapeToText(true);
        textBox.setTextBoxWrapMode(TextBoxWrapMode.NONE);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text fit tightly inside textbox");
        
        builder.moveTo(textBoxShape.getParentParagraph());
        
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Set margins for the textbox
        textBox.setInternalMarginTop(15.0);
        textBox.setInternalMarginBottom(15.0);
        textBox.setInternalMarginLeft(15.0);
        textBox.setInternalMarginRight(15.0);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text placed according to textbox margins");
        
        doc.save(getArtifactsDir() + "Drawing.TextBox.docx");
      • getInternalMarginLeft/setInternalMarginLeft

        public double getInternalMarginLeft() / public void setInternalMarginLeft(double value)
        
        Specifies the inner left margin in points for a shape.

        The default value is 1/10 inch.

        Example:

        Shows how to insert text boxes and arrange their text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a shape that contains a TextBox
        Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        TextBox textBox = textBoxShape.getTextBox();
        
        // Move the document builder to inside the TextBox and write text
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Vertical text");
        
        // Text is displayed vertically, written top to bottom
        textBox.setLayoutFlow(LayoutFlow.TOP_TO_BOTTOM_IDEOGRAPHIC);
        
        // Move the builder out of the shape and back into the main document body
        builder.moveTo(textBoxShape.getParentParagraph());
        
        // Insert another TextBox
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
        textBox.setFitShapeToText(true);
        textBox.setTextBoxWrapMode(TextBoxWrapMode.NONE);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text fit tightly inside textbox");
        
        builder.moveTo(textBoxShape.getParentParagraph());
        
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Set margins for the textbox
        textBox.setInternalMarginTop(15.0);
        textBox.setInternalMarginBottom(15.0);
        textBox.setInternalMarginLeft(15.0);
        textBox.setInternalMarginRight(15.0);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text placed according to textbox margins");
        
        doc.save(getArtifactsDir() + "Drawing.TextBox.docx");
      • getInternalMarginRight/setInternalMarginRight

        public double getInternalMarginRight() / public void setInternalMarginRight(double value)
        
        Specifies the inner right margin in points for a shape.

        The default value is 1/10 inch.

        Example:

        Shows how to insert text boxes and arrange their text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a shape that contains a TextBox
        Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        TextBox textBox = textBoxShape.getTextBox();
        
        // Move the document builder to inside the TextBox and write text
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Vertical text");
        
        // Text is displayed vertically, written top to bottom
        textBox.setLayoutFlow(LayoutFlow.TOP_TO_BOTTOM_IDEOGRAPHIC);
        
        // Move the builder out of the shape and back into the main document body
        builder.moveTo(textBoxShape.getParentParagraph());
        
        // Insert another TextBox
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
        textBox.setFitShapeToText(true);
        textBox.setTextBoxWrapMode(TextBoxWrapMode.NONE);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text fit tightly inside textbox");
        
        builder.moveTo(textBoxShape.getParentParagraph());
        
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Set margins for the textbox
        textBox.setInternalMarginTop(15.0);
        textBox.setInternalMarginBottom(15.0);
        textBox.setInternalMarginLeft(15.0);
        textBox.setInternalMarginRight(15.0);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text placed according to textbox margins");
        
        doc.save(getArtifactsDir() + "Drawing.TextBox.docx");
      • getInternalMarginTop/setInternalMarginTop

        public double getInternalMarginTop() / public void setInternalMarginTop(double value)
        
        Specifies the inner top margin in points for a shape.

        The default value is 1/20 inch.

        Example:

        Shows how to insert text boxes and arrange their text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a shape that contains a TextBox
        Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        TextBox textBox = textBoxShape.getTextBox();
        
        // Move the document builder to inside the TextBox and write text
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Vertical text");
        
        // Text is displayed vertically, written top to bottom
        textBox.setLayoutFlow(LayoutFlow.TOP_TO_BOTTOM_IDEOGRAPHIC);
        
        // Move the builder out of the shape and back into the main document body
        builder.moveTo(textBoxShape.getParentParagraph());
        
        // Insert another TextBox
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
        textBox.setFitShapeToText(true);
        textBox.setTextBoxWrapMode(TextBoxWrapMode.NONE);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text fit tightly inside textbox");
        
        builder.moveTo(textBoxShape.getParentParagraph());
        
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Set margins for the textbox
        textBox.setInternalMarginTop(15.0);
        textBox.setInternalMarginBottom(15.0);
        textBox.setInternalMarginLeft(15.0);
        textBox.setInternalMarginRight(15.0);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text placed according to textbox margins");
        
        doc.save(getArtifactsDir() + "Drawing.TextBox.docx");
      • getLayoutFlow/setLayoutFlow

        public int getLayoutFlow() / public void setLayoutFlow(int value)
        
        Determines the flow of the text layout in a shape. The value of the property is LayoutFlow integer constant.

        The default value is LayoutFlow.HORIZONTAL.

        Example:

        Shows how to insert text boxes and arrange their text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a shape that contains a TextBox
        Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        TextBox textBox = textBoxShape.getTextBox();
        
        // Move the document builder to inside the TextBox and write text
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Vertical text");
        
        // Text is displayed vertically, written top to bottom
        textBox.setLayoutFlow(LayoutFlow.TOP_TO_BOTTOM_IDEOGRAPHIC);
        
        // Move the builder out of the shape and back into the main document body
        builder.moveTo(textBoxShape.getParentParagraph());
        
        // Insert another TextBox
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
        textBox.setFitShapeToText(true);
        textBox.setTextBoxWrapMode(TextBoxWrapMode.NONE);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text fit tightly inside textbox");
        
        builder.moveTo(textBoxShape.getParentParagraph());
        
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Set margins for the textbox
        textBox.setInternalMarginTop(15.0);
        textBox.setInternalMarginBottom(15.0);
        textBox.setInternalMarginLeft(15.0);
        textBox.setInternalMarginRight(15.0);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text placed according to textbox margins");
        
        doc.save(getArtifactsDir() + "Drawing.TextBox.docx");
      • getNext/setNext

        public TextBox getNext() / public void setNext(TextBox value)
        
        Returns or sets a TextBox that represents the next TextBox in a sequence of shapes.
      • getParent

        public Shape getParent()
        
        Gets a parent shape for the TextBox.
      • getPrevious

        public TextBox getPrevious()
        
        Returns a TextBox that represents the previous TextBox in a sequence of shapes.
      • getTextBoxWrapMode/setTextBoxWrapMode

        public int getTextBoxWrapMode() / public void setTextBoxWrapMode(int value)
        
        Determines how text wraps inside a shape. The value of the property is TextBoxWrapMode integer constant.

        The default value is TextBoxWrapMode.SQUARE.

        Example:

        Shows how to insert text boxes and arrange their text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a shape that contains a TextBox
        Shape textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        TextBox textBox = textBoxShape.getTextBox();
        
        // Move the document builder to inside the TextBox and write text
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Vertical text");
        
        // Text is displayed vertically, written top to bottom
        textBox.setLayoutFlow(LayoutFlow.TOP_TO_BOTTOM_IDEOGRAPHIC);
        
        // Move the builder out of the shape and back into the main document body
        builder.moveTo(textBoxShape.getParentParagraph());
        
        // Insert another TextBox
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Apply these values to both these members to get the parent shape to defy the dimensions we set to fit tightly around the TextBox's text
        textBox.setFitShapeToText(true);
        textBox.setTextBoxWrapMode(TextBoxWrapMode.NONE);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text fit tightly inside textbox");
        
        builder.moveTo(textBoxShape.getParentParagraph());
        
        textBoxShape = builder.insertShape(ShapeType.TEXT_BOX, 100.0, 100.0);
        textBox = textBoxShape.getTextBox();
        
        // Set margins for the textbox
        textBox.setInternalMarginTop(15.0);
        textBox.setInternalMarginBottom(15.0);
        textBox.setInternalMarginLeft(15.0);
        textBox.setInternalMarginRight(15.0);
        
        builder.moveTo(textBoxShape.getLastParagraph());
        builder.write("Text placed according to textbox margins");
        
        doc.save(getArtifactsDir() + "Drawing.TextBox.docx");
      • getVerticalAnchor/setVerticalAnchor

        public int getVerticalAnchor() / public void setVerticalAnchor(int value)
        
        Specifies the vertical alignment of the text within a shape. The value of the property is TextBoxAnchor integer constant.

        The default value is TextBoxAnchor.TOP.

        Example:

        Shows how to change text position inside textbox shape.
        Document doc = new Document(getMyDir() + "Shape.GetTextBoxAndChangeAnchor.docx");
        NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
        
        Shape textbox = (Shape) shapes.get(0);
        textbox.getTextBox().setVerticalAnchor(TextBoxAnchor.BOTTOM);
        
        doc.save(getArtifactsDir() + "Shape.GetTextBoxAndChangeAnchor.docx");
    • Method Detail

      • breakForwardLink

        public void breakForwardLink()
        Breaks the link to the next TextBox. BreakForwardLink() doesn't break all other links in the current sequence of shapes. For example: 1-2-3-4 sequence and BreakForwardLink at the 2-nd textbox will create two sequences 1-2, 3-4.
      • isValidLinkTarget

        public boolean isValidLinkTarget(TextBox target)
        Determines whether this TextBox can be linked to the target Textbox.