向下移动表:itextsharp

时间:2012-12-10 05:30:44

标签: asp.net-mvc asp.net-mvc-4 itextsharp

我正在使用iTextSharp生成pdf。

我的代码是,

 public FileStreamResult Export(int ID)
    {
        MemoryStream stream = new MemoryStream();
        Document pdf = new Document();
        PdfWriter writer = PdfWriter.GetInstance(pdf, stream);
        pdf.Open();
        //code for table
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
        cell.Colspan = 3;
        cell.HorizontalAlignment = 1;
        table.SpacingBefore = 100;   //not working
        table.SpacingAfter = 10;     //not working
        table.AddCell(cell);
        table.AddCell("Col 1 Row 1");
        table.AddCell("Col 2 Row 1");
        table.AddCell("Col 3 Row 1");
        table.AddCell("Col 1 Row 2");
        table.AddCell("Col 2 Row 2");
        table.AddCell("Col 3 Row 2");

        pdf.Add(table);


        pdf.Close();

        //code to download 
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename="+_child[0].Child_Name+".pdf");
        Response.Buffer = true;
        Response.Clear();
        Response.OutputStream.Write(stream.GetBuffer(), 0, stream.GetBuffer().Length);
        Response.OutputStream.Flush();
        Response.End();

        return new FileStreamResult(Response.OutputStream, "application/pdf");
    } 

该表格显示在页面顶部。但我想把桌子移下来。我怎么办?

请帮助,

感谢。

1 个答案:

答案 0 :(得分:1)

您只需添加一个' f'在固定值的最后。

例:

table.SpacingBefore = 100f;   //is working 
table.SpacingAfter = 10f;     //is working