I am trying to add text with three alignment options i.e., Top, Bottom, Centre.
Sample code:
var doc = new Document(“d://Input.pdf”);
var textValue = “Test Address”;Page page = doc.Pages[1];
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);// First Text box (TOP)
Aspose.Pdf.Drawing.Rectangle rectfirst = new Aspose.Pdf.Drawing.Rectangle(127.949623, 571.9400634765625, 139.511337, 35.4562454);
var colorName = ColorTranslator.FromHtml("#FFFF00");
rectfirst.Text = new TextFragment(textValue);
rectfirst.Text.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
rectfirst.GraphInfo.Color = Aspose.Pdf.Color.FromRgb(colorName);
canvas.Shapes.Add(rectfirst);// SECOND Text box (CENTER)
Aspose.Pdf.Drawing.Rectangle rectsecond = new Aspose.Pdf.Drawing.Rectangle(277.4811, 571.9400634765625, 139.511337, 35.4562454);
rectsecond.Text = new TextFragment(textValue);
rectsecond.GraphInfo.Color = Aspose.Pdf.Color.FromRgb(colorName);
canvas.Shapes.Add(rectsecond);// Third Text box (bottom)
Aspose.Pdf.Drawing.Rectangle rectThird = new Aspose.Pdf.Drawing.Rectangle(427.0126, 571.9400634765625, 139.511337, 35.4562454);
rectThird.Text = new TextFragment(textValue);
rectThird.Text.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Bottom;
rectThird.GraphInfo.Color = Aspose.Pdf.Color.FromRgb(colorName);
canvas.Shapes.Add(rectThird);doc.Pages[1].Paragraphs.Add(canvas);
doc.Save(“d://output.pdf”);
input.pdf (206.4 KB)
output.pdf (268.1 KB)
However, using the above code all the text comes in the centre.
Is there any way the text inside rectangle can be aligned top, bottom or centre?