繁体   English   中英

如何在Aspose.PDF .NET中旋转表格单元格中的文本

[英]How to Rotate Text in Table Cell in Aspose.PDF .NET

我正在使用Aspose.PDF .NET 10.4(撰写本文时为最新)。 我正在使用他们的DOM API(不赞成使用生成器)。

如何将表格单元中的文本逆时针旋转90度?

这是我尝试过的方法,但是在矩形上旋转没有影响。

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");

怎么样:

row.Cells[0].VerticalTextRotationAngle = VerticalTextRotationType.AntiClockWise;

从最新发布的Aspose.Pdf 17.5开始 ,可以添加旋转的文本片段。 将角度值(以度为单位)设置为TextState.Rotation属性。

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");

我叫Nayyer,我是Aspose的开发人员。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM