[reportlab-users] Pagenumbers and table of contents
Sebastian Ware
sebastian at urbantalk.se
Fri Oct 12 05:02:20 EDT 2007
How about creating a flowable, which doesn't render any visual
artifacts, called...
TocEntry(info, list_name)
...where info is a dictionary that can be accessed when creating the
item in the rendered TOC (such as title, outline level). Name is the
name of the TOC, so one could use it for several reference lists in
the document. The TocEntry() is added wherever I want to be able to
reference something.
When I have added all my TocEntry() items, I could access
self.getTocEntries(list_name) and create my TOC...
style = ...
toc_story = []
for entry in self.getTocEntries('toc'):
toc_story.append( TocItem(entry.info['title'], entry, style,
leftIndent= 0, sep= ' ') )
Then I would have to insert the toc_story in the right place of my
document story. The TocItem() renders with the specified style +
leftIndent, followed by repeating sep and then a right justified
pagenumber. Of course one could create ones own customised TocItem
that renders differently, but this is flexible enough for most cases.
This will probably only require a single pass when rendering. The
number of TocEntry items is known and each height too, then only the
page numbers need to be added after the entire document has been
rendered.
If we also add entry_name...
TocEntry(info, list_name, entry_name= None)
...and the method self.getTocDictionaryItem(list_name, entry_name),
we could reference a specific item. And if this is and maybe this
would allow us to reference TocEntry() items that are created later
in the document. Useful for inline references to tables etc.
This should probably not be too difficult to implement and maintain,
yet it is dead easy to understand for a newbie like myself.
Mvh Sebastian
11 okt 2007 kl. 22.11 skrev Andy Robinson:
> On 11/10/2007, Sebastian Ware <sebastian at urbantalk.se> wrote:
>> Hi!
>>
>> Can I use SimpleDocTemplate() to create a TOC? How would I specify
>> the toc-items and get the automatic page numbers?
>
> SimpleDocTemplate inherits from BaseDocTemplate so you can specialise
> it in the same way. It just saves you defining your own frames when
> you only want one.
>>
>> I have seen test_platypus_toc.py but it requires me to specialise
>> BaseDocTemplate. Is this the only way?
>
> Regrettably there is no easy way to do these. We still have to remind
> ourselves
> every time.
>
> If anyone can suggest a nicer API for creating indices and tables -
> how to specify what you want indexing - I'd consider implementing it.
> Right now it's a PITA. Sorry!
>
>> I also read about something called namedString and getName, but
>> couldn't get it to work.
>> http://developer.reportlab.com/rsrc/rml_examples/
>> test_012_simpletoc.pdf
>
> Report Markup Language is our commercial software and works a bit
> differently; in markup-land it's easier to do a preprocessing pass
> than in Python.
>
> If you are using TinyRML or z3c.rml, you'd have to ask the
> implementers. If you are working for one of our customers and using
> RML(tm), or want to discuss pricing for a real project, we'd be happy
> to talk offline (and could provide proper teaching examples).
>
> Best Regards,
>
> Andy Robinson
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
More information about the reportlab-users
mailing list