问题

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