如何在itext7表格单元格中插入换行符

问题描述 投票:0回答:1

如何在itext7表格单元格中插入换行符?这是我的代码,

PdfWriter writer = new PdfWriter(@"C:\Temp\test123.pdf");
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf, PageSize.LEGAL);
string msg = $"This is line 1{Environment.NewLine}This should be line 2, However it's not showing";
Table table = new Table(1, true);
Cell cell = new Cell().Add(new Paragraph(msg));
table.AddCell(cell);
document.Add(table);
document.Close();
Process.Start(@"C:\Temp\test123.pdf");
c# itext7
1个回答
3
投票

在使用像Paragraph这样的PDF生成工具时,通常应该使用iText而不是手动设置换行符。

var cell = new Cell();
cell.Add(new Paragraph("This is line 1");
cell.Add(new Paragraph("This should be line 2, and it is!~");
© www.soinside.com 2019 - 2024. All rights reserved.