【问题标题】:Itextsharp Next line in paragraph coming right below serial numberItextsharp 段落中的下一行在序列号正下方
【发布时间】:2013-07-12 08:15:10
【问题描述】:

我正在使用 iTextSharp 生成 PDF。给出序列号后,我有一些笔记要写在页面上。我正在使用Paragraph。但是段落中的下一行正好在序列号下方。只有在进入下一行时,我才能定义段落的边距或填充?

我的代码

for(int i=0;i<list.count;i++)
{
    doc.Add(new Paragraph(String.Format("{0}) {1} ({2}).", (i + 1).ToString(), "Here Goes My String", "Date Time"), font));
}

i 是序列号。

【问题讨论】:

  • 你能画一个简单的图像来说明你正在尝试做什么,从你的描述中不太清楚。
  • 你好 @ChrisHaas 我已经上传了我的 pdf 部分的图像。现在 pdf 中的下一行正好在序列号下,即 1 ,我希望这一行被填充或指定边距以便它看起来不错跨度>

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


【解决方案1】:

与其将列表项添加到段落,不如创建 itextsharp 的列表项并将其添加到 listItem 的 Arraylist。您可以创建有序和无序列表项,类似于 HTML 对应项 &lt;ul&gt;&lt;ol&gt;

检查以下代码:

  iTextSharp.text.List list = new iTextSharp.text.List(iTextSharp.text.List.ORDERED, 20f);
  list.IndentationLeft = 20f;//indented 20 points from left margin
  list.Add("The RomanList is added to the ordered list, and iTextSharp indents the RomanList relative to the ordered list to which it belongs");
  list.Add("The RomanList is added to the ordered list, and iTextSharp indents the RomanList relative to the ordered list to which it belongs");
  list.Add("Three");
  pdfDoc.Add(list);//add list to document

以上代码将创建有序列表。第二个参数将 symbolIndent 设置为 20 磅,这导致数字和项目本身之间的空间。

要了解有关使用 Itextsharp 创建列表的更多信息,请查看以下链接:

http://www.mikesdotnetting.com/Article/83/Lists-with-iTextSharp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-04
    • 2011-04-20
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 2018-06-02
    相关资源
    最近更新 更多