1 minute to read
convertToDocx
At a Glance

Before You Begin
Before using this task:
-
Install pandoc.
-
Ensure that 'docbook' and 'docx' are added to the inputFiles formats in Config.groovy.
-
As an optional step, specify a reference doc file with custom stylesheets (see task
createReferenceDoc
).
Further Reading and Resources
Read the Render AsciiDoc to docx (MS Word) blog post.
Source
pandoc.gradle
task convertToDocx (
group: 'docToolchain',
description: 'converts file to .docx via pandoc. Needs pandoc installed.',
type: Exec
) {
// All files with option `docx` in config.groovy is converted to docbook and then to docx.
def sourceFilesDocx = sourceFiles.findAll { 'docx' in it.formats }
sourceFilesDocx.each {
def sourceFile = it.file.replace('.adoc', '.xml')
def targetFile = sourceFile.replace('.xml', '.docx')
workingDir "$targetDir/docbook"
executable = "pandoc"
if(referenceDocFile?.trim()) {
args = ["-r","docbook",
"-t","docx",
"-o","../docx/$targetFile",
"--reference-doc=${docDir}/${referenceDocFile}",
sourceFile]
} else {
args = ["-r","docbook",
"-t","docx",
"-o","../docx/$targetFile",
sourceFile]
}
}
doFirst {
new File("$targetDir/docx/").mkdirs()
}
}
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.