I’m trying to position text within a rectangle and am unsuccessful. I’ve included an example program below. Please let me know what I’m doing wrong. Thank you for your time.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Rectangle = Aspose.Pdf.Drawing.Rectangle;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
var doc = new Document();
var page = doc.Pages.Add();
var canvas = new Graph(100, 400);
page.Paragraphs.Add(canvas);
var textRect = new Aspose.Pdf.Drawing.Rectangle(30, 75, 150, 50);
textRect.GraphInfo.Color = Aspose.Pdf.Color.BlanchedAlmond;
textRect.GraphInfo.DashArray = new int[] { 1 };
var tf = new TextFragment("Test It!")
{
Position = new Position(30, 30),
BaselinePosition = new Position(70, 70),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Bottom
};
tf.TextState.Font = FontRepository.FindFont("Whitney Book");
tf.TextState.FontSize = 12;
tf.TextState.BackgroundColor = Aspose.Pdf.Color.FloralWhite;
tf.TextState.ForegroundColor = Aspose.Pdf.Color.DarkBlue;
tf.TextState.FontStyle = FontStyles.Regular;
tf.TextState.StrikeOut = false;
tf.TextState.Underline = false;
tf.TextState.DrawTextRectangleBorder = true;
textRect.Text = tf;
canvas.Shapes.Add(textRect);
doc.Save("drawing.pdf");
}
}
}