Hi guys,
I wonder if it’s possible to set the point of origin when rotating a text fragment?
Here is my code:
TextBuilder textBuilder = new TextBuilder(page);
var list = new System.Collections.Generic.List<Field>();
int[] angles = { 0, 90, 180, 270 };
foreach (var i in angles)
{
var field1 = new Field
{
Text = i + " degrees",
Rotation = i,
LocationX = 220,
LocationY = 150,
ActualFontSizeF = 12,
ActualHeight = 26,
ActualWidth = 120
};
list.Add(field1);
}
foreach (Field field in list)
{
// Control font size is in pixel. Multiplier is an estimate to convert pixel to float.
var fontSize = (float)(field.ActualFontSizeF * 0.755);
// Create text fragment
var textFragment = new TextFragment(field.Text);
textFragment.TextState.Font = FontRepository.FindFont("Verdana");
textFragment.TextState.FontSize = fontSize;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
// create text paragraph
TextParagraph paragraph = new TextParagraph();
// specify the location to add TextParagraph
paragraph.Rectangle = new Aspose.Pdf.Rectangle(
Aspose.Words.ConvertUtil.PixelToPoint(field.LocationX + adjustment, b.HorizontalResolution),
(pageHeight - Aspose.Words.ConvertUtil.PixelToPoint(field.LocationY + field.ActualHeight, b.VerticalResolution)),
Aspose.Words.ConvertUtil.PixelToPoint(field.LocationX + field.ActualWidth - adjustment, b.HorizontalResolution),
(pageHeight - Aspose.Words.ConvertUtil.PixelToPoint(field.LocationY, b.VerticalResolution)));
paragraph.VerticalAlignment = VerticalAlignment.Top;
paragraph.Rotation = -(field.Rotation);
paragraph.AppendLine(textFragment);
textBuilder.AppendParagraph(paragraph);
}
document.Save(dataDir + "Sample_FontAngle_out.pdf");
I have also attached the output I got from the above code. Noticed that the rotated text are outside the boxes. The text having 0 angle looks fine.
Sample_FontAngle_out.pdf (57.5 KB)
Can you please advise on this?
Kind regards,
Byang