Itextsharp Next line in paragraph coming right below serial number

蓝咒 提交于 2019-12-11 14:57:54

问题


I am working on generating PDF using iTextSharp. I have some notes to be written on the page after giving a serial number. I am using Paragraph. But next line in paragraph comes right under serial number. How can I define margins or padding to paragraph only if it goes to next line?

My code

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 is the serial number.


回答1:


Rather adding your list items to paragraph, create List items of itextsharp and add it to Arraylist of listItem. You can create Ordered and Unorder list item, similar to HTML counterpart <ul> and <ol>

Check below code:

  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

Above code will create ordered list. Second argument sets symbolIndent to 20 points, this results in to the space between number and the item itself.

To know more about creating lists with Itextsharp, check out below link:

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



来源:https://stackoverflow.com/questions/17610483/itextsharp-next-line-in-paragraph-coming-right-below-serial-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!