Search code examples
pythonepubrfc

Generating epub from xml2rfc programmatically


I'm using xml2rfc to write the RFC for NetJSON, I found out it is possible to export the RFC in epub format through the online service xml2rfc.ietf.org, but I haven't found an easy way to do this programmatically without using the online service.

I use a script to automatically update the RFC draft in HTML version that is linked on the website, I would really love to do the same for an ePub version, at the moment I do not link the epub version on the website because I have to update it manually, which is time consuming, so I do it sporadically.

Are there any tools that might help me in this situation?


Solution

  • xml2rfc does not support epub, the webpage mentions

    EPub support is provided using version 0.8 of ebook-convert.

    PS and RTF support are provided using a combination of wkhtmltopdf, pdf2ps and/or GNU enscript.

    You can try libraries like EbookLib (installed through pip) or you can run calibre as a process.

    Update: Actually, it is one-line command after all.

    Install calibre (Ubuntu 15.10 in my case):

    sudo apt-get install calibre  
    

    Run command (doc) (this is from epub to other format, but you can do it the other way around)

    ebook-convert Metamorphosis-jackson.epub something.pdf
    

    You can choose from various output formats. (http://manual.calibre-ebook.com/cli/ebook-convert.html#epub-output-options)


    Output:

    1% Converting input to HTML...
    InputFormatPlugin: EPUB Input running
    on /home/<user>/other/xml2rfc/Metamorphosis-jackson.epub
    Found HTML cover OEBPS/front-cover.html
    Parsing all content...
    MediaQuery: Unknown media type "amzn-kf8".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    MediaQuery: Unknown media type "amzn-mobi".
    34% Running transforms on ebook...
    Merging user specified metadata...
    Detecting structure...
            Detected chapter: CHAPTER I
            Detected chapter: CHAPTER II
            Detected chapter: CHAPTER III
    Flattening CSS and remapping font sizes...
    Source base font size is 12.00000pt
    Removing fake margins...
    Cleaning up manifest...
    Trimming unused files from manifest...
    Creating PDF Output...
    67% Running PDF Output plugin
    The cover image has an id != "cover". Renaming to work around bug in Nook Color
    71% Rendered title-page.html
    76% Rendered copyright.html
    81% Rendered table-of-contents.html
    85% Rendered pressbooks-promo.html
    90% Rendered chapter-001-chapter-i.html
    95% Rendered chapter-002-chapter-ii.html
    100% Rendered chapter-003-chapter-iii.html
    Rendered PDF in 0.915601 seconds:
    PDF output written to /home/<user>/other/xml2rfc/something.pdf
    Output saved to   /home/<user>/other/xml2rfc/something.pdf