我正在使用iText 7 C#来构建一个pdf. 这就是我的问题..我正试着在最后一排添加一个日期.因为我没有太多的空间,所以我试着垂直旋转它.但文本正在换行到下一行.此外,我希望文本正好位于单元格的中心(旋转后垂直和水平).我可以像‘/’一样稍微向右转吗?

// add signed date row
table.AddCell(new Cell().Add(new Paragraph("")).SetWidth(UnitValue.CreatePercentValue(1 * 5)).SetBorder(Border.NO_BORDER));
table.AddCell(new Cell().Add(new Paragraph("")).SetWidth(UnitValue.CreatePercentValue(7 * 5)).SetBorder(Border.NO_BORDER));
index = 0;
foreach (var month in months)
{
    var dateCell = new Cell().SetWidth(UnitValue.CreatePercentValue(1 * 5))
                            .Add(new Paragraph("3/5/23")).SetFontSize(8);
    dateCell.SetRotationAngle(Math.PI/2);
    table.AddCell(dateCell);
    index++;
 }

enter image description here

推荐答案

这应该可以完成工作,包括文本对齐和防止单词换行

var dateCell = new Cell().SetWidth(UnitValue.CreatePercentValue(1 * 5))
        .SetHeight(UnitValue.CreatePercentValue(30)) // Adjust the cell height as needed
        .SetTextAlignment(TextAlignment.CENTER) // Set text alignment to center
        .SetPaddingBottom(10) // Adjust the bottom padding as needed
        .Add(new Paragraph("3/5/23")).SetFontSize(8);

    // Adjust rotation angle to make it fall slightly to the right
    dateCell.SetRotationAngle(Math.PI / 4);

备注中的替代选项

var paragraph = new Paragraph("3/5/23");

// Adjust rotation angle to make it fall slightly to the right    
paragraph.SetRotationAngle(Math.PI / 4);

var dateCell = new Cell().SetWidth(UnitValue.CreatePercentValue(1 * 5))
        .SetHeight(UnitValue.CreatePercentValue(30)) // Adjust the cell height as needed
        .SetTextAlignment(TextAlignment.CENTER) // Set text alignment to center
        .SetPaddingBottom(10) // Adjust the bottom padding as needed
        .Add(paragraph).SetFontSize(8);

Csharp相关问答推荐

Rx.Net -当关闭序列被触发时如何聚合消息并发出中间输出?

子组件:如何根据另一个组件的状态启用输入

O(N)测试失败

在C#中使用in修饰符

CS0103 dlibdotnet和www.example.com facerect不在上下文中

为什么C#Bigbit不总是相同的比特长度?

如何使用新的Microsoft.IdentityModel.JsonWebToken创建JwtSecurityToken?

为什么我的表单在绑定到对象时提交空值?

JSON空引用异常仅在调试器中忽略try-Catch块,但在其他上下文中捕获得很好

单行上的ReSharper数据标注

当前代码Cosmos DB 3.37.1:PartitionKey key key mismatch exception

如果是,我怎么才能让这个加75,如果不是,我怎么才能减go 100?

C#自定义验证属性未触发IsValid方法

C#按名称从类获取属性值类型<;t>;,我需要反射吗?

当空判断结果赋给变量时,为什么会出现可能空异常警告的解引用?

数据库.Migrate在对接容器重启时失败

ASP.NET MVC数据批注验证组复选框

WPF:如何从DatagridHeader的内容模板绑定到词典项

如何在Cake脚本中设置MSBuild.exe的绝对路径

使用ITfoxtec.Identity.Saml2解析相同键多值SAML 2声明