Calibre (and produce and publish)

I have set up Produce and Publish to export ebooks with Calibre.

After the e-pub is made, I need to open the Ebook in Calibre Ebook edit and add the front cover and generate the TOC (Clicking on generate TOC from major headings work perfect).

I am pretty sure that this can be done from the command line, but I can not figure out from where the conversion is run).

.... any help is welcome... even if you have to bill me... or need help with something in return.

Produce & Publish - likely you are talking about the Produce & Publish Plone Client Connector - does nothing ebook related. The conversion is carried out on the Produce & Publish Server which wraps the ebook-convert binary. If you can accomplish your goal yourself with ebook-convert then it should be possible to do the same through the PP server and its API. Most supported converters support arbitrary command line options to be passed through the Python API to the REST endpoint of the PP server.

-aj

Looking at the pp.server code: is this what the 'cmd_options' is for ?

So in theory, it should be possible to use:
http://site/page/@@asPDF?converter=calibre&-cover=/path/to/cover.jpg

or
http://site/page/@@asPDF?converter=calibre&cmd_options=[-cover=/path/to/cover.jpg]

'producing':

ebook-convert in.html out.epub -cover=/path/to/cover.jpg

( cover has to be an image in calibre convert, it can not be html )

The pdf() method

accepts on the API level the cmd_options parameter (which is just a string).

This parameter is not used and not fetch from the request...feel free to add it in your fork.

However the parameter is passed through the Python API

https://bitbucket.org/ajung/pp.client-python/src/0b37660bc2ab968c7bee8a79fc7e7c3807e6dfcd/pp/client/python/pdf.py?at=master&fileviewer=file-view-default#pdf.py-58

down to the converter level
https://bitbucket.org/ajung/pp.server/src/aff9ad2deae4a712f38ed1ca787b1a57770837a4/pp/server/converters.py?at=master&fileviewer=file-view-default#converters.py-159

-aj

1 Like

Excellent!
I think I got it now.

For later reference:

Typical parameters for the cover will be:

" --remove-first-image --cover=%s" % cover

where cover is path to an image

Typical TOC (table of contents) would be something like:

" --level1-toc=//h:h1 --level2-toc=//h:h2  --level3-toc=//h:h3"

the language can be set with:

" --language=%s" % language

resulting in something like this:

ebook-convert "/path/to/var/queue/af523db3-87b3-4e40-a3d5-e4391fcafa44/index.html" 
"/path/to/pp.server/var/queue/af523db3-87b3-4e40-a3d5-e4391fcafa44/out/out.epub"  
--remove-first-image --cover=http://mysite/page/@@images/image --level1-toc=//h:h1 
--level2-toc=//h:h2  --level3-toc=//h:h3 --language=no