Convert Maven Site Software Documentation to PDF

2.8k views Asked by At

I am currently working on a project written in Java and I am using Maven and the maven-site-plugin to generate a website containing all the relevant JavaDoc, reports, etc. I am needing at the same time to be able to convert the same documentation into a readable, book-like format. Are there any scripts or tools out there designed to take a website, and convert it into a reasonably formatted PDF or other style so that it can be easily given digitally or printed out?

1

There are 1 answers

2
Rich Seller On BEST ANSWER

The maven-pdf-plugin generates a PDF of the project documentation.

Two notes from the documentation to consider:

Note 1: By default, the PDF plugin generates a PDF document which aggregates all your site documents. If you want to generate each site document individually, you need to add -Daggregate=false in the command line.

Note 2: By default, the PDF plugin uses the FOP implementation. The plugin also supports the iText implementation, you just need to add -Dimplementation=itext in the command line.

You can actually specify the aggregate property in your POM (see example below).

This configuration will generate the PDF on each build that the docs profile is active (you could do it on every build, but it would be a bit slow for your typical development cycle:

<profiles>
  <profile>
    <id>docs</id>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-pdf-plugin</artifactId>
      <version>1.0</version>
      <executions>
        <execution>
          <id>pdf</id>
          <phase>site</phase>
          <goals>
            <goal>pdf</goal>
          </goals>
          <configuration>
            <outputDirectory>
              ${project.reporting.outputDirectory}
            </outputDirectory>
            <aggregate>false</aggregate>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </profile>
</profiles>

You can activate the profile on the command line with -P docs or use an activation configuration if you want to be finer-grained.