Is it possible to place text inside a rectangle?

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v10)  /  Is it possible to place text inside a rectangle?

DynamicPDF CoreSuite for .NET (v10) Forum

MergeDocument doc = new MergeDocument("D:\\TestData\\OMTI_NDB Assure_SOC2_EngLtr__01 17 2020 vf.pdf");
                        
Rectangle rectangle = new Rectangle(100, 100, 50, 50);
rectangle.BorderStyle = LineStyle.Solid;
rectangle.CornerRadius = 5;
rectangle.FillColor = RgbColor.Yellow;
rectangle.ID = "Exhibit 1 Rectangle";

TextArea textArea = new TextArea("Exhibits 1", 105, 105, 40, 40);
textArea.ID = "Exhibit 1 Text";

doc.Pages[0].Elements.Add(rectangle);
doc.Pages[0].Elements.Add(textArea);

This works, but it is difficult to align the text.
Is there a better way?
Posted by a ceTe Software moderator
Hello,

You can achieve this by setting the rectangles x, y width and height based on the same values used for the TextArea then using the align and vAlign properties of the TextArea. Here is a code sample:

    MergeDocument doc = new MergeDocument(@"Input PDF file path");

    Rectangle rectangle = new Rectangle(105, 105, 60, 50);
    rectangle.BorderStyle = LineStyle.Solid;
    rectangle.CornerRadius = 5;
    rectangle.FillColor = RgbColor.Yellow;
    rectangle.ID = "Exhibit 1 Rectangle";

    TextArea textArea = new TextArea("Exhibits 1", 105, 105, 60, 50);
    textArea.ID = "Exhibit 1 Text";
    textArea.Align = TextAlign.Center;
    textArea.VAlign = VAlign.Center;

    doc.Pages[0].Elements.Add(rectangle);
    doc.Pages[0].Elements.Add(textArea);

    doc.Draw(@"Output PDF file path");

Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 7:29 PM.