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

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download an input file

using System;
using System.IO;
using System.Linq;
using GemBox.Document;
using GemBox.Document.Drawing;

class Sample
    static void Main(string[] args)
        // If using Professional version, put your serial key below.

        DocumentModel document = DocumentModel.Load("TextBoxes.docx");

        var textBox = new TextBox(document,
                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.Save("Text Boxes.docx");
Imports System
Imports System.IO
Imports System.Linq
Imports GemBox.Document
Imports GemBox.Document.Drawing

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.

        Dim document As DocumentModel = DocumentModel.Load("TextBoxes.docx")

        Dim textBox = New TextBox(document,
                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.docx")

    End Sub

End Module