【问题标题】:How to Rotate Text in Table Cell in Aspose.PDF .NET如何在 Aspose.PDF .NET 中旋转表格单元格中的文本
【发布时间】:2015-06-08 01:52:53
【问题描述】:

我正在使用 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");

【问题讨论】:

  • 您好 Dirq,我是 Aspose 的开发人员布道师。我还设法重现了上述问题,根据我的观察,表格单元格内的文本没有被旋转。为了更正,我已将其作为 PDFNEWNET-38829 记录在我们的问题跟踪系统中。我们将进一步调查此问题的详细信息,并将向您发布更正状态。

标签: c# .net pdf aspose aspose.pdf


【解决方案1】:

怎么样:

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

【讨论】:

  • 嗨,史蒂夫,Dirq 正在使用 Aspose.Pdf 命名空间的新 DOM 方法,并且 VerticalTextRotationAngle 属性存在于旧版 Aspose.Pdf.Generator 命名空间中。所以恐怕上述解决方案不适用于新的 DOM 方法。
【解决方案2】:

从最近发布的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 的开发人员传道者。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    相关资源
    最近更新 更多