Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate PDF from docbook XML when building Java project using Gradle

I need to generate a PDF version of the docbook.xml documentation (5.0) when building the java project using gradle (build.gradle file).

If someone could show an example of a script that will work on any platform (Mac OS X, Windows, Linux) that would be very helpful.

like image 911
Roger Avatar asked Nov 25 '11 21:11

Roger


1 Answers

Ok, so finally I found the solution. In order to generate a PDF, you have to provide the following files :

  • The docbook file (.XML)
  • An XSL stylesheet file (.XSL)
  • The docbook.gradle file that you can grab from here: https://github.com/SpringSource/spring-build-gradle/blob/master/docbook.gradle
  • The build.gradle file

You have to add after to build.gradle the line

apply from: "docbook.gradle"

after

apply plugin: "java"

Then, append to the end of build.gradle this:

docbookPdf {
    sourceFileName = "docbook.xml"
    stylesheet = file("doc/docbook-style.xsl")
    sourceDirectory = file( "doc" )
    docsDir = new File(project.getBuildDir(), "docs");
}

Here, we've put the docbook.xml and docbook-style.xsl in rootDirectory/doc, and we put the generated PDF in rootDirectory/docs (/pdf).

Here is an example of a docbook stylesheet that you can use: http://cl.ly/2n1p3o0r1L3Z1d2U4345

To generate the PDF, from the terminal, go to the directory where the file build.gradle is and execute

gradle docbookPdf

if you named the task 'docbookPdf'.

That's it. It should work on any platform.

like image 193
Roger Avatar answered Oct 12 '22 09:10

Roger