2
我在使用iTextSharp重叠表时遇到问题。iTextSharp绝对定位(GridView)
我有多个表格(来自gridviews),我想用iTextSharp写入pdf。
我想每个表之间只有10px的间距(垂直方向),并且表的高度总是不同。
有没有人有文章我可以阅读,以帮助我与这种情况?或者有什么建议?绝对定位不适合我。
我在使用iTextSharp重叠表时遇到问题。iTextSharp绝对定位(GridView)
我有多个表格(来自gridviews),我想用iTextSharp写入pdf。
我想每个表之间只有10px的间距(垂直方向),并且表的高度总是不同。
有没有人有文章我可以阅读,以帮助我与这种情况?或者有什么建议?绝对定位不适合我。
您可以将每个表格放在iTextSharp.text.Paragraph
中,并使用Paragraph
对象的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();
}
}
这应该告诉你可以做什么。尝试添加和删除第一个表中的行;你会看到两个表格之间的空间总是在那里,并没有改变。
废话,非常感谢你!大声笑。 – Kukoy 2010-09-30 16:07:36