英文:
iText 7 - cell text rotation
问题
I am using iText 7 C# to build a pdf.
Here is my issue.. I am trying to add a date to the last row. Since I do not have much space available I am trying to rotate it vertically.. but the text is wrapping to the next line. Also, I wanted the text to be exactly center of cell (vertically and horizontally after the rotation). Can I have the rotation slightly fall to the right like '/'?
// 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++;
}
英文:
I am using iText 7 C# to build a pdf.
Here is my issue.. I am trying to add a date to the last row. Since I do not have much space available I am trying to rotate it vertically.. but the text is wrapping to the next line. Also, I wanted the text to be exactly center of cell (vertically and horizontally after the rotation). Can I have the rotation slightly fall to the right like '/'?
// 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++;
}
答案1
得分: 1
这应该可以胜任工作,包括TextAlignment和防止换行的设置。
var dateCell = new Cell().SetWidth(UnitValue.CreatePercentValue(1 * 5))
.SetHeight(UnitValue.CreatePercentValue(30)) // 根据需要调整单元格高度
.SetTextAlignment(TextAlignment.CENTER) // 将文本对齐方式设置为居中
.SetPaddingBottom(10) // 根据需要调整底部填充
.Add(new Paragraph("3/5/23")).SetFontSize(8);
// 调整旋转角度使其稍微向右倾斜
dateCell.SetRotationAngle(Math.PI / 4);
// 从注释中的替代方法
var paragraph = new Paragraph("3/5/23");
// 调整旋转角度使其稍微向右倾斜
paragraph.SetRotationAngle(Math.PI / 4);
var dateCell = new Cell().SetWidth(UnitValue.CreatePercentValue(1 * 5))
.SetHeight(UnitValue.CreatePercentValue(30)) // 根据需要调整单元格高度
.SetTextAlignment(TextAlignment.CENTER) // 将文本对齐方式设置为居中
.SetPaddingBottom(10) // 根据需要调整底部填充
.Add(paragraph).SetFontSize(8);
希望这对你有所帮助!如果有任何其他问题,请随时提出。
英文:
This should do the job, including the TextAlignment and preventing of word wrap
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);
Alternative from comment
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论