Place text on document

Trying to place text on given dimensions inside a page. Trying to use the textbox function as a floating element but having trouble styling it for my needs. Anyone that can point me in the right direction?
I need to remove the border, padding / margin, set font size, font name. Also need to remove the edit mode that seams to be active when saving to pdf?

Its the text 1:100 that I need to style some way, the layout behind is an svg placed on the document with floating layout.


Hi Anders,

Try this:

var textbox = new TextBox(document, new FloatingLayout(
    new HorizontalPosition(450, LengthUnit.Point, HorizontalPositionAnchor.Page),
    new VerticalPosition(750, LengthUnit.Point, VerticalPositionAnchor.Page),
    new Size(60, 30)));

// Remove borders and margins.
textbox.TextBoxFormat.InternalMargin = new Padding(0);

// Set vertical alignment.
textbox.TextBoxFormat.VerticalAlignment = VerticalAlignment.Center;

var paragraph = new Paragraph(document);

// Set horizontal alignment.
paragraph.ParagraphFormat.Alignment = HorizontalAlignment.Center;

var run = new Run(document, "1:100");

// Set font size and font name.
run.CharacterFormat.Size = 18;
run.CharacterFormat.FontName = "Arial";

Unfortunately, I’m not sure what you mean by that.
Can you try explaining exactly what you’re referring to?


The edit mode is when Adobe PDF is viewing the document. Can this be disabled or is it default for Adobe PDF?

Adjusted the code a bit, could perhaps font size and font name be set using a style that is reusable?

public void AddText(string text, double x, double y, double width, double height, Paragraph paragraph)
            var textBox = new TextBox(Document, new FloatingLayout(
                new HorizontalPosition(x, LengthUnit.Millimeter, HorizontalPositionAnchor.Page),
                new VerticalPosition(y, LengthUnit.Millimeter, VerticalPositionAnchor.Page),
                new Size(width, height, LengthUnit.Millimeter)));

            // Remove borders and margins.
            textBox.TextBoxFormat.InternalMargin = new Padding(0);

            // Set vertical alignment.
            textBox.TextBoxFormat.VerticalAlignment = VerticalAlignment.Center;

            //Add new paragraph to textBox
            var paragraphInsideTextBox = new Paragraph(Document);

            // Set horizontal alignment.
            paragraphInsideTextBox.ParagraphFormat.Alignment = HorizontalAlignment.Left;
            var run = new Run(Document, text);

            // Set font size and font name.
            run.CharacterFormat.Size = 10;
            run.CharacterFormat.FontName = "Arial";

The passed in paragraph is defined in a ctor for the “report”. What’s the best practice here, should I reuse the paragraph defined in the ctor of the report class for many floating layout or should one add new paragraph at the “main” level of a section for each floating layout?

            var paragraph = new Paragraph(Document);
            _paragraph = paragraph;


The size of a textbox, knowing the exact size that a text needs on creation, know of any way to determine this or ?

Hi Anders, I still don’t know what you mean by edit mode, but it seems to be something related to Adobe Acrobat.

Regarding the styles, please check this example:

And this documentation page:

Regarding the paragraphs, you cannot reuse them.
Please check the content model diagram of the DocumentModel object:

Regarding the textbox size, you can use auto-fit properties of the TextBoxFormat, see its members: