We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to rotate text in a cell (using DOM)

In the older Generator namespace, we used to rotate in a Cell like so:


Cell cell1Row1 = row1.Cells.Add(FieldValueText);

cell1Row1.VerticalTextRotationAngle = VerticalTextRotationType.AntiClockWise;


I see an older support message about this, but I’m not seeing how to render a cell with rotated text yet.

Please advise,

Thanks!

@mjk1813,
The VerticalTextRotationAngle property of the Cell class is not available in the new DOM approach. You can add a TextFragment node in the table’s cell to rotate text. Please try the following code:

[C#]

 //Instantiate Pdf instance by calling its empty constructor
Document document = new Document();
//Add page to PDF object
Aspose.Pdf.Page page = document.Pages.Add();
// rotate text
TextFragment fragment = new TextFragment("rotated text");
fragment.TextState.Rotation = 45;
//create a table object
Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
//Specify the columns width information for table object
table1.ColumnWidths = "200 200";
//Add Paragraph
page.Paragraphs.Add(table1);
Aspose.Pdf.Row row2 = table1.Rows.Add();
Aspose.Pdf.Cell cell1Row2 = row2.Cells.Add();
cell1Row2.Paragraphs.Add(fragment);
// Save the resultant PDF document
document.Save(@"C:\Pdf\test227\Output.pdf");

This is the output PDF: Output.pdf (2.0 KB). Kindly let us know in case of any further assistance or questions.

Best Regards,
Imran Rafique

Thanks Imran.
I see the general idea here, but if I change the rotation to 90 degrees, the text is always truncated within the cell. I tried playing with the ColumnWidths and alignments, but “rotated text” always turns into “ro”.
What should I do to adjust the position of the text within the cell?
Thanks in advance!

@mjk1813,
Thank you for the inquiry. You can adjust the Row height as below:

[C#]

Aspose.Pdf.Row row2 = table1.Rows.Add();
row2.MinRowHeight = 200;

Best Regards,
Imran Rafique