在使用itextsharp生成的pdf中,C#中的表格格式不可见

本文关键字:表格 格式 pdf itextsharp | 更新日期: 2023-09-27 18:26:12

在使用itextsharp生成的pdf中,C#中对表进行的格式化不可见。

我正在做如下格式化:

Table table = new Table();
table.BorderStyle = BorderStyle.Solid;
table.Style.Add("width", "696");
table.BorderStyle = BorderStyle.Solid;
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.BorderStyle = BorderStyle.Solid;
Unit ut = new Unit(2);
cell.BorderWidth = ut;
cell.BorderColor = Color.Black;

但我的pdf仍然是在没有任何格式的情况下生成的。我的表格以pdf格式显示。但是没有应用任何格式。

知道吗?

在使用itextsharp生成的pdf中,C#中的表格格式不可见

您似乎喜欢添加一个黑色边框,并将表宽度设置为696。

PdfPTable table = new PdfPTable(1);
table.TotalWidth = 696f;
PdfPCell cell = new PdfPCell(new Phrase("Hello World!", new Font(Font.ARIAL, 12f, Font.NORMAL, Color.BLACK)));
cell.BorderColor = new Color(0,0,0);
cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
cell.BorderWidthLeft = 2f;
cell.BorderWidthRight = 2f;
table.AddCell(cell);