Search Results for

    Show / Hide Table of Contents

    Text frames

    Version 6.1.0

    In this article

    • Introduction
    • Margins
    • Orientation
    • Further options

    This article describes how text frames are added to a MigraDoc document to add content with full control of its position.

    Introduction

    Content like paragraphs and tables are usually added to the text flow of a document. By wrapping it in a text frame, you gain control to place it anywhere on the page. As the TextFrame class derives from Shape, you can use all the functionality explained in Formats / Sizing & positioning.

    You can create a text frame containing some text like this:

    // Add a TextFrame.
    var textFrame = section.AddTextFrame();
    …
    // Add some text.
    textFrame.AddParagraph("A simple TextFrame");
    

    See full WrappingContent sample in PDFsharp.Sample repository. Show resulting PDF

    You can also add multiple paragraphs or call the AddImage or the AddTable functions to add other content to the text frame.

    If not specified, a text frame will have a default size of 2.5 x 2.5 centimeters. A text frame never grows with its content, so you should always set the desired size (see Formats / Sizing & positioning for more information).

    Margins

    You can easily define the margins between the borders of the text frame and its content:

    // Set the margins.
    textFrame.MarginTop = Unit.FromCentimeter(0.5);
    textFrame.MarginRight = Unit.FromCentimeter(1);
    textFrame.MarginBottom = Unit.FromCentimeter(1.5);
    textFrame.MarginLeft = Unit.FromCentimeter(2);
    

    See full Margins sample in PDFsharp.Sample repository. Show resulting PDF

    The margin properties are of the type Unit (see Formats / Unit for more information).

    You can also use the Margin property to set all margins to the same value:

    // Set a margin.
    textFrame.Margin = Unit.FromCentimeter(1);
    

    See full Margins sample in PDFsharp.Sample repository. Show resulting PDF

    Margin is a property of the type Unit (see Formats / Unit for more information).

    Orientation

    The content of a text frame can be rotated left or right using the Orientation property. So you can wrap text, an image or a table in a text frame to extend it with this rotation functionality. The default value of Orientation is TextOrientation.Horizontal.

    If you set it to TextOrientation.Upward, the content is rotated 90 degrees to the left, so that the text flows upwards:

    // Change its orientation.
    textFrame.Orientation = TextOrientation.Upward;
    

    See full Orientation sample in PDFsharp.Sample repository. Show resulting PDF

    If you set it to TextOrientation.Downward, the content is rotated 90 degrees to the right, so that the text flows downwards:

    // Change its orientation.
    textFrame.Orientation = TextOrientation.Downward;
    

    See full Orientation sample in PDFsharp.Sample repository. Show resulting PDF

    Note that only the content and its internal text flow is rotated. So, using TextOrientation.Downward, the content will start at the upper right corner instead of the upper left. All size and margin values, however, are not rotated.

    Further options

    There are some more functionalities to manage the text frame that are not described here, as they apply to all Shape derived objects. These are:

    • Size and position (see Formats / Sizing & positioning)
    • Line format (see Formats / Borders & line format)
    • Fill format (see Formats / Shading & fill format)
    • Edit this page
    In this article
    Generated by DocFX  |   Privacy policy  |   Legal notice
    Back to top