itext - How can I add titles of chapters in ColumnText? -


please, how can add titles of chapters in columntext? need make pdf this:

    |    columntext column1   |    columntext column2   |     | pdfptable content  |  pdfptable content |     |                         |      chapter 2 title    |     |     chapter 1 title     |                         | 

and add toc document. make document columntext , table in it. can't add chapter in table. can add chapter document body, in case title of chapter not in columntext.

image of 1 page of result document here

your question isn't clear in sense don't tell if want toc this:

enter image description here

if case, using wrong terminology, see in bookmarks panel can referred outlines or bookmarks.

if want toc, want this:

enter image description here

i mention both, because talk chapter (a class should no longer use) , class creates bookmarks/outlines, not toc.

i have create pdf file has both, bookmarks , toc: columns_with_toc.pdf. please take @ createtocincolumn example find out how it's done.

just you, create columntext object titles , tables:

columntext ct = new columntext(writer.getdirectcontent()); int start; int end; (int = 0; <= 20; ) {     start = (i * 10) + 1;     i++;     end = * 10;     string title = string.format("numbers %s %s", start, end);     chunk c = new chunk(title);     c.setgenerictag(title);     ct.addelement(c);     ct.addelement(createtable(start, end)); } int column = 0; {     if (column == 3) {         document.newpage();         column = 0;     }     ct.setsimplecolumn(columns[column++]); } while (columntext.hasmoretext(ct.go())); 

the result looks this:

enter image description here

in spite of rules posting question on stackoverflow, didn't post code sample, there @ least 1 difference between code , mine:

c.setgenerictag(title); 

in line, declare generic tag. tag used tocentry class looks this:

public class toccreation extends pdfpageeventhelper {      protected pdfoutline root;     protected list<tocentry> toc = new arraylist<tocentry>();      public toccreation() {     }      public void setroot(pdfoutline root) {         this.root = root;     }      public list<tocentry> gettoc() {         return toc;     }      @override     public void ongenerictag(pdfwriter writer, document document, rectangle rect, string text) {         pdfdestination dest = new pdfdestination(pdfdestination.xyz, rect.getleft(), rect.gettop(), 0);         new pdfoutline(root, dest, text);         tocentry entry = new tocentry();         entry.action = pdfaction.gotolocalpage(writer.getpagenumber(), dest, writer);         entry.title = text;         toc.add(entry);     } } 

as can see, create pdfdestination based on position of title:

pdfdestination dest = new pdfdestination(pdfdestination.xyz, rect.getleft(), rect.gettop(), 0); 

if want bookmarks, can create pdfoutline this:

new pdfoutline(root, dest, text); 

if want toc, can store string , pdfaction in list:

tocentry entry = new tocentry(); entry.action = pdfaction.gotolocalpage(writer.getpagenumber(), dest, writer); entry.title = text; toc.add(entry); 

now understand toccreation class, take @ how use it:

pdfwriter writer = pdfwriter.getinstance(document, new fileoutputstream(dest)); toccreation event = new toccreation(); writer.setpageevent(event); document.open(); event.setroot(writer.getrootoutline()) 

we create event object, pass writer , after we've opened document, pass root of outline tree event. bookmarks created automatically, toc won't. if want add toc, need this:

document.newpage(); (tocentry entry : event.gettoc()) {     chunk c = new chunk(entry.title);     c.setaction(entry.action);     document.add(new paragraph(c)); } 

you have list of titles can click jump corresponding table.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -