2

I'm using Aspose.PDF .NET 10.4 (latest as of this writing). I'm using their DOM api (not generator as that's deprecated).

How do I rotate text in a table cell 90 degrees counterclockwise?

Here's what I tried but the rotation on a rectangle had no affect.

Table table =  new Table();
table.DefaultCellBorder = new BorderInfo(BorderSide.All, 1f, Color.Black);
table.DefaultCellPadding = new MarginInfo(5, 5, 5, 5);

var headerRow = table.Rows.Add();
headerRow.FixedRowHeight = 100;
headerRow.DefaultCellTextState.HorizontalAlignment = HorizontalAlignment.Center;

for (int hc = 0; hc < 20; hc++)
{
    var cell = headerRow.Cells.Add();
    cell.BackgroundColor = Color.Red;
    cell.DefaultCellTextState.ForegroundColor = Color.White;
    cell.DefaultCellTextState.FontStyle = FontStyles.Bold;

    var h = new TextFragment("header-" + hc);
    h.Rectangle.Rotate(270); //this does nothing
    cell.Paragraphs.Add(h);
}

for (int r = 0; r < 15; r++)
{
    var row = table.Rows.Add();
    for (int c = 0; c < 20; c++)
    {
        row.Cells.Add(r + "-" + c);
    }
}

Document doc = new Document();
Page page = doc.Pages.Add();
page.Paragraphs.Add(table);
doc.Save("c:\temp\table.pdf");
dirq
  • 968
  • 2
  • 11
  • 26
  • Hi Dirq, I am a developer evangelist at Aspose. I have also managed to reproduce the above stated issue and as per my observations, the text inside table cell is not being rotated. For the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-38829. We will further look into the details of this issue and will keep you posted on the status of correction. – codewarior Jun 08 '15 at 12:13

2 Answers2

0

How about something like:

row.Cells[0].VerticalTextRotationAngle = VerticalTextRotationType.AntiClockWise;
SteveFerg
  • 3,466
  • 7
  • 19
  • 31
  • Hi Steve, Dirq is using new DOM approach of Aspose.Pdf namespace and the VerticalTextRotationAngle property is present in legacy Aspose.Pdf.Generator namespace. So I am afraid the above stated solution will not work with new DOM approach. – codewarior Jun 08 '15 at 12:11
0

Starting the recent release of Aspose.Pdf 17.5 it is possible to add rotated text fragments. Set angle value in degrees to TextState.Rotation property.

string myDir = @"D:\Temp\000\";
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1f, Aspose.Pdf.Color.Black);
table.DefaultCellPadding = new Aspose.Pdf.MarginInfo(5, 5, 5, 5);

Row headerRow = table.Rows.Add();
headerRow.FixedRowHeight = 100;
headerRow.DefaultCellTextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;

for (int hc = 0; hc < 4; hc++)
{
    Cell cell = headerRow.Cells.Add();
    cell.BackgroundColor = Aspose.Pdf.Color.Red;
    cell.DefaultCellTextState.ForegroundColor = Aspose.Pdf.Color.White;
    cell.DefaultCellTextState.FontStyle = FontStyles.Bold;

    TextFragment h = new TextFragment("header-" + hc);

    //Set rotation
    h.TextState.Rotation = 270;

    cell.Paragraphs.Add(h);
}

for (int r = 0; r < 15; r++)
{
    Row row = table.Rows.Add();
    for (int c = 0; c < 4; c++)
    {
        row.Cells.Add(r + "-" + c);
    }
}

Document doc = new Document();
Page page = doc.Pages.Add();
page.Paragraphs.Add(table);
doc.Save(myDir + "TextRotate_inCell_17_5.pdf");

My name is Nayyer and I am developer evangelist at Aspose.

codewarior
  • 441
  • 2
  • 9