设置PdfPTable与标题间的距离

使用itextsharp生成PDF时,需要改变标题与文档中添加的PdfPTable间距离,改变SpacingBefore值不起作用,查了下这方面的知识较少,自己跟踪代码,找到了设置位置是在使用iTextSharp.text.Document时,如:

using iTextSharp.text.pdf;
using iTextSharp.text;

//创建Pdf文档
m_Doc = new Document(DefaultPageSize, 40f, 40f, 100f, 20f);  

其中100f就是内容距上边距的距离 ,若设置200f 则标题与文档中生成的PdfPTable间距离变大。

上面方法适合于改变 模板。

当然也可以改变单个PDF文档,不过还有一个间接的方法改变单个PDF文档中标题与文档中添加的PdfPTable间距离:

在添加的PdfPTable最上方添加不显示边框的字符串为空的行(一排单元格)。如下:

 

PdfPCell cell;

String gcInfo = string.Empty;
font = ITextPdfHelper.GetFont(12);
cell = new PdfPCell(new Paragraph(gcInfo, font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_BOTTOM;
cell.Border = Rectangle.NO_BORDER;
cell.Colspan = 9; // 标段名称 占一行
pdfTable.AddCell(cell);


String bdInfo = string.Empty;
font = ITextPdfHelper.GetFont(12);
cell = new PdfPCell(new Paragraph(bdInfo, font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_BOTTOM;
cell.Border = Rectangle.NO_BORDER;
cell.Colspan = 9; //2014-10-13 标段名称 占一行
pdfTable.AddCell(cell);

posted @ 2014-10-20 14:06  慧由心生  阅读(10211)  评论(1编辑  收藏  举报