【问题标题】:ITextSharp 4.1.6. PDF Table - how to remove whitespace on top of each cell? [padding and leading already set to 0]ITextSharp 4.1.6。 PDF表格 - 如何删除每个单元格顶部的空格? [填充和前导已设置为 0]
【发布时间】:2012-03-29 03:30:42
【问题描述】:

ITextSharp 的表格有问题。我想要没有顶部和底部填充的单元格,以便它们彼此靠近。

虽然我已将单元格的填充和前导设置为 0,但空白仍然存在。

请问有人知道怎么去掉空格吗?

编辑:

感谢 Dylan 的及时回答,我已经设法解决了我的问题。如果有人遇到类似问题,这是源 sn-p

        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

【问题讨论】:

标签: c# pdf itext cellpadding


【解决方案1】:

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

例如:

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

或

cell.UseAscender = true;

请粘贴您的代码。

【讨论】:

  • 也为我工作,已经尝试解决了几个小时 - 好问题,好答案!
  • @bigtv - 我在同一条船上......但我们的天父一如既往地将我带到了正确的位置。很好的答案迪伦。
  • UseAscender 有效。这个图书馆让我想跳进太阳。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多