2014-02-12 31 views
1

創建內iTextSharp的嵌套列表是簡單iTextSharp的 - )名單中的多個級別(

var list = new List(true); 
list.add("Something here"); 
list.add("Something else here"); 
var nestedList = new List(true); 
nestedList.add("Some other value"); 
list.add(nestedList); 
document.add(list); // assuming here of course you have 
        // created an instance of Document()! 

會產生非常基本的,如

  1. 的東西在這裏
  2. 別的東西在這裏
      東西
    1. 其他值

我想創造一些更復雜的東西;我創建其中有條款和分條款的文件,以便要列出每個列表項是這樣的:

1. Parent list item 
1.1 Something here 
1.2 Something else here 

,但我不能在任何地方看到的API,其中這是可能的範圍內。我認爲這樣做的唯一方法是使用Paragraph(),但是有其他人會遇到更優雅的解決方案嗎?

感謝

回答

2

我可以看到這樣做是手動跟蹤父嵌套和使用PreSymbol屬性來設置它的唯一途徑。

如下:

   List list = new List(List.ORDERED, 20f); 
       list.IndentationLeft = 20f; 

       // add sublist 
       List subList = new List(List.ORDERED); 
       subList.PreSymbol = string.Format("{0}.", i); 
       subList.Add("Something here"); 
       subList.Add("Something else here"); 

       list.Add(subList); 

       doc.Add(list); 

這將導致:

Screen grab

+0

對不起,這不是我想要的。我知道如何嵌套列表,但我想具體有1.1和1.2。我會更新我的問題以反映這一點。 – Matt

+0

@Matt我已更新我的問題,以顯示我知道的唯一方法。如果這不好,請讓我知道,我會刪除它,因爲downvote從我的聲譽中脫穎而出。似乎沒有辦法從api中確定父級,除非我錯過了它:http://api.itextpdf.com/itext/com/itextpdf/text/List.html – hutchonoid

+1

@hutchoniod這是正是我想要的。非常感謝你! – Matt