it is extremely complicated when it shouldn't be. maybe someday someone will make a saas to solve this problem once & forever.
i've wrote custom code for it that i'll share maybe 1 day but not yet.
what i did was use markdown with node.js & wrote a script that all chapters are read from it.
it looks like this:
_book/ chapter1/ pic1.jpg index.md chapter2/ . . . chapter100/
and then it uses princexml with 100 loc of css to output a beautiful pdf.
this should definitely be a saas though. it has massive potential.