Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iTextSharp绝对定位(GridView)_C#_.net_Itextsharp - Fatal编程技术网

C# iTextSharp绝对定位(GridView)

C# iTextSharp绝对定位(GridView),c#,.net,itextsharp,C#,.net,Itextsharp,我在使用iTextSharp重叠桌子时遇到问题 我有多个表(来自GridView),我想使用iTextSharp将其写入pdf 我只希望每个桌子之间有10px的间隙(垂直方向),并且桌子的高度总是不同的 有没有人能给我读一篇文章来帮助我解决这个问题?或者有什么建议?绝对定位对我不起作用。您可以将每个表放在iTextSharp.text.paragration中,并使用paragration对象的SpacingAfter属性创建间距 与此试验方法类似: private static void De

我在使用iTextSharp重叠桌子时遇到问题

我有多个表(来自GridView),我想使用iTextSharp将其写入pdf

我只希望每个桌子之间有10px的间隙(垂直方向),并且桌子的高度总是不同的


有没有人能给我读一篇文章来帮助我解决这个问题?或者有什么建议?绝对定位对我不起作用。

您可以将每个表放在
iTextSharp.text.paragration
中,并使用
paragration
对象的
SpacingAfter
属性创建间距

与此试验方法类似:

private static void DemoTableSpacing() {
    using (FileStream fs = new FileStream("SpacingTest.pdf", FileMode.Create)) {

        Document doc = new Document();
        PdfWriter.GetInstance(doc, fs);
        doc.Open();

        Paragraph paragraphTable1 = new Paragraph();
        paragraphTable1.SpacingAfter = 15f;

        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Phrase("This is table 1"));
        cell.Colspan = 3;
        cell.HorizontalAlignment = 1;
        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");
        paragraphTable1.Add(table);
        doc.Add(paragraphTable1);

        Paragraph paragraphTable2 = new Paragraph();
        paragraphTable2.SpacingAfter = 10f;

        table = new PdfPTable(3);
        cell = new PdfPCell(new Phrase("This is table 2"));
        cell.Colspan = 3;
        cell.HorizontalAlignment = 1;
        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");
        paragraphTable2.Add(table);
        doc.Add(paragraphTable2);
        doc.Close();
    }
}
这应该表明你能做什么。尝试在第一个表中添加和删除行;您将看到两个表之间的空间始终存在,并且不会改变