The kerning is indeed off in the calibre pdf, I suspect that has to do with the font used, Qt is rather finicky about what fonts it renders well. calibre is perfectly capable of generating multi-level tocs, you just need to set the appropriate conversion options. You can also control margins, justification and set a special stylesheet. And calibre uses the Qt WebKit rendering engine, which means it's support for CSS is likely to be pretty good
Anyway, I was just curious. Regarding your original questions, if you make it a standalone plugin you will need to do more work --- get the file from the database, explode the epub yourself and so on. SO make it a conversionplugin.
The conversion plugin is called witht eh book already exploded into its individual files, in an "oeb" object. Just have a look at one of the simpler conversion output plugins in calibre to see how to use the oeb object. For example, the rtf or txt output plugins. Or the htmlz output plugin. And feel free to ask if you need clarification.