iTextSharp pdf表格单元格高度问题

时间:2013-11-15 10:31:18

标签: layout pdf-generation itextsharp

我有iTextSharp 5.4.4(nuget)并且有一个带有条形码(ean13)的漂亮表格和下面的文字。 我有特定的tablecell高度(和单元格宽度),因为我想将pdf打印到带有贴纸的A4。 这是当前的布局:

enter image description here

正如您所看到的,ean13代码和下面的文本之间存在相当大的差距。 这是我的C#代码:

PdfPCell c = new PdfPCell();
c.FixedHeight = 21.2f * postScriptPointsPerMilimeter; // to get to accurate milimeters
c.HorizontalAlignment = Element.ALIGN_CENTER;

Paragraph p = new Paragraph();
p.Font.Size = 6;
Chunk code = new Chunk(dr["productcode"].ToString());
p.Alignment = Element.ALIGN_CENTER;
p.Add(code);

BarcodeEAN ean13 = new BarcodeEAN();
ean13.CodeType = BarcodeEAN.EAN13;
ean13.Code = dr["ProductEan13"].ToString();
ean13.BarHeight = 4.0f * postScriptPointsPerMilimeter;
var a = ean13.CreateImageWithBarcode(cb, null, null);
a.ScalePercent(90);

c.AddElement(a);
c.AddElement(p);

t.AddCell(c);

我的问题是减少条形码和文本之间的空间。我无法看到它是否与条形码的边距或段落或两者都有关...难以排除故障。

1 个答案:

答案 0 :(得分:1)

p.Leading = 0;

那是失踪的。我以为

p.SpacingBefore = 0;

会做到这一点,但事实并非如此。 Leading做了!

相关问题