Text Boxes

Text Boxes give you control over the position of a block of text in your document.

Following example shows how GemBox.Document reads Text Boxes and their properties (fill, outline, etc.) from DOCX and how to add new Text Box to the document with GemBox.Document API.

For more information about Text Boxes, see Shapes and Layout help page.

Text Boxes Screenshot
Upload your file (Drag file here)
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("%InputFileName%");

        var textBox = new TextBox(document,
            Layout.Floating(
                new HorizontalPosition(HorizontalPositionType.Right, HorizontalPositionAnchor.Margin),
                new VerticalPosition(VerticalPositionType.Bottom, VerticalPositionAnchor.Margin),
                new Size(4, 3.5, LengthUnit.Centimeter)),
            new Paragraph(document, "Text Box created with GemBox.Document."),
            new Paragraph(document, "It has default fill and outline."));

        document.Sections[0].Blocks.Cast<Paragraph>(0).Inlines.Add(textBox);

        document.Save("Text Boxes.%OutputFileType%");
    }
}
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("%InputFileName%")

        Dim textBox = New TextBox(document,
            Layout.Floating(
                New HorizontalPosition(HorizontalPositionType.Right, HorizontalPositionAnchor.Margin),
                New VerticalPosition(VerticalPositionType.Bottom, VerticalPositionAnchor.Margin),
                New Size(4, 3.5, LengthUnit.Centimeter)),
            New Paragraph(document, "Text Box created with GemBox.Document."),
            New Paragraph(document, "It has default fill and outline."))

        document.Sections(0).Blocks.Cast(Of Paragraph)(0).Inlines.Add(textBox)

        document.Save("Text Boxes.%OutputFileType%")

    End Sub

End Module

Check next example or download examples from GitHub.