0

我正在使用 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");
    } 

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

请帮忙,

谢谢。

4

1 回答 1

1

您只需f在固定值的末尾添加一个 ' '。

示例:

table.SpacingBefore = 100f;   //is working 
table.SpacingAfter = 10f;     //is working
于 2014-03-16T22:02:37.697 回答