ItextSharp 4.1.6。PDF表 - 如何在每个单元格上删除空格?[填充和领先已设置为0]

StackOverflow https://stackoverflow.com//questions/9672046

  •  12-12-2019
  •  | 
  •  

我有itextharp的表有问题。我想在没有顶部和底部填充的情况下有细胞,使它们彼此更靠近。

虽然我已经将填充物和小区的前导设置为0,但空白仍然存在。

是否有人请知道如何删除空格?

编辑:

thanx要及时回答迪伦,我设法解决了我的问题。如果有人遇到类似的问题

,这是源片段
        Document document = new Document(PageSize.A4, 5, 5, 10, 10);
        using (FileStream fs = new FileStream("C:\\Users\\brum\\Desktop\\untitled.pdf", FileMode.Create))
        {
            iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs);
            document.Open();
            PdfPTable table = new PdfPTable(2);
            PdfPCell cell = new PdfPCell(new Phrase("Spanning 2 cols"));

            cell.Colspan = 2;
            cell.HorizontalAlignment = 1;
            cell.Padding = 0f;
            cell.UseAscender = true;
            table.AddCell(cell);

            table.AddCell("Next row 1");
            table.AddCell("Next row 2");

            document.Add(table);
            document.Close();
        }
.

cell.UseAscender = true; // This is the line that did the trick for me

有帮助吗?

解决方案

将顶部填充设置为小或甚至负面。另一种选择是 PdfPCell.setUseAscender()

前:

cell.setPaddingTop(0f);  // No padding on top cell
.

cell.UseAscender = true;
.

请粘贴您的代码。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top