Text Boxes

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

Following sample 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.

Screenshot

Text Boxes Screenshot

See the full code below, use RUN EXAMPLE to execute.

Upload your file (Drag files here)

1using System;
2using System.IO;
3using System.Linq;
4using GemBox.Document;
5using GemBox.Document.Drawing;
6
7class Sample
8{
9    [STAThread]
10    static void Main(string[] args)
11    {
12        // If using Professional version, put your serial key below.
13        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
14
15        DocumentModel document = DocumentModel.Load("TextBoxes.docx");
16
17        var textBox = new TextBox(document,
18            Layout.Floating(
19                new HorizontalPosition(HorizontalPositionType.Right, HorizontalPositionAnchor.Margin),
20                new VerticalPosition(VerticalPositionType.Bottom, VerticalPositionAnchor.Margin),
21                new Size(4, 3.5, LengthUnit.Centimeter)),
22            new Paragraph(document, "Text Box created with GemBox.Document."),
23            new Paragraph(document, "It has default fill and outline."));
24
25        document.Sections[0].Blocks.Cast<Paragraph>(0).Inlines.Add(textBox);
26
27        document.Save("Text Boxes.docx");
28    }
29}
1Imports System
2Imports System.IO
3Imports System.Linq
4Imports GemBox.Document
5Imports GemBox.Document.Drawing
6
7Module Samples
8
9    Sub Main()
10
11        ' If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
13
14        Dim document As DocumentModel = DocumentModel.Load("TextBoxes.docx")
15
16        Dim textBox = New TextBox(document,
17            Layout.Floating(
18                New HorizontalPosition(HorizontalPositionType.Right, HorizontalPositionAnchor.Margin),
19                New VerticalPosition(VerticalPositionType.Bottom, VerticalPositionAnchor.Margin),
20                New Size(4, 3.5, LengthUnit.Centimeter)),
21            New Paragraph(document, "Text Box created with GemBox.Document."),
22            New Paragraph(document, "It has default fill and outline."))
23
24        document.Sections(0).Blocks.Cast(Of Paragraph)(0).Inlines.Add(textBox)
25
26        document.Save("Text Boxes.docx")
27
28    End Sub
29
30End Module

Check next sample or find out more about GemBox.Document and GemBox Software.