Johannes Thorn Jody Winter Jody Winter Jeremie Bresson Ralf D. Müller Dr. Stefan Pfeiffer Lars Francke

1 minute to read


About This Task

This task uses pandoc to convert the DocBook output from AsciiDoctor to ePub. This publishes the output as an eBook which can be read using any eBook reader. The resulting file can be found in build/docs/epub.

Further Reading and Resources


Show source code of scripts/pandoc.gradle or go directly to GitHub · docToolchain/scripts/pandoc.gradle.
task convertToEpub (
        group: 'docToolchain',
        description: 'converts file to .epub via pandoc. Needs pandoc installed.',
        type: Exec
) {
    // All files with option `epub` in config.groovy is converted to docbook and then to epub.
    def sourceFilesEpub = sourceFiles.findAll { 'epub' in it.formats }
    def explicitSourceFilesCount = sourceFilesEpub.size()
        sourceFilesEpub = sourceFiles.findAll { 'docbook' in it.formats }
    sourceFilesEpub.each {
        def sourceFile = it.file.replace('.adoc', '.xml')
        def targetFile = sourceFile.replace('.xml', '.epub')

        new File("$targetDir/epub/$targetFile")

        workingDir "$targetDir/docbook"
        executable = "pandoc"
        args = ['-r','docbook',
    doFirst {
            throw new Exception ("""
            >> No source files defined for type 'epub'.
            >> Please specify at least one inputFile in your docToolchainConfig.groovy
        if(explicitSourceFilesCount==0) {
            logger.warn('WARNING: No source files defined for type "epub". Converting with best effort')