gpt4 book ai didi

c# - 如何在 iTextSharp\iText 中的两个元素之间添加空格\边距?

转载 作者:IT王子 更新时间:2023-10-29 04:32:48 25 4
gpt4 key购买 nike

我是 iTextSharpt(C# 的 iText 移植)的新手,我有以下疑问。

在我的代码中有类似的东西:

iTextSharp.text.Paragraph titolo = new iTextSharp.text.Paragraph(currentVuln.Title, _fontTitolo0);
titolo.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
_document.Add(titolo);

table = new PdfPTable(3);
table.WidthPercentage = 98;

cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
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");

_document.Add(table);

如您所见,我只是打印了一个标题(使用段落对象)并在其下方放置了一个表格。

问题是我的标题和表格之间没有空格(边距),图形效果不好,这是我在生成的 PDF 中得到的:

enter image description here

如何在标题段落和表格之间添加一些空格\边距?最好的方法是什么?我正在尝试这样做,但直到现在,我还没有找到解决方案

谢谢

最佳答案

您有几个不同的选择。您可以在段落上设置 SpacingAfter:

titolo.SpacingAfter = 20;

您还可以在表格上设置 SpacingBefore:

table.SpacingBefore = 20;

或者您可以在段落中添加一些回车:

iTextSharp.text.Paragraph titolo = new iTextSharp.text.Paragraph("Hello World\n\n");

关于c# - 如何在 iTextSharp\iText 中的两个元素之间添加空格\边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22909227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com