Generate PDF docs from Markdown files during the Maven build

Viewed 1702

I have a Java project with the Maven Assembly plugin. The Assembly Plugin builds a final ZIP release file that contains binary (*.war), config files and some PDF documentation.

The documents are written in Markdown and the PDF docs for the release need to be generated manually (ex. with Markdown to PDF online tool) before I execute the build with Maven. Then the Assembly plugin takes the PDFs and put them to the final ZIP.

Almost every time when I create a release ZIP file, I forgot to generate PDFs manually so usually the final ZIP contains old documentation. This is so bad.

I would like to automate PDF generation. I have checked four MD to PDF maven plugins, but none of them works fine. I have found a plugin to generates MD to HTML (without any default stylesheet) and maybe I can use another plugin to convert HTML to PDF, but it is so painful.

What I tried:

Is there any easy way to generate PDF files with Maven, based on the Markdown files during the build process?

1 Answers

This way you are able to generate the pdf on linux, if you want to run it on Windows as well, add a profile and pass the profile on build time.

  <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>pandoc</id>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>                            
            </executions>
            <configuration>
                <executable>pandoc</executable>
                <workingDirectory></workingDirectory>
                <arguments>
                    <argument>-o</argument>
                    <argument>README.pdf</argument>
                    <argument>README.md</argument>
                </arguments>
            </configuration>
        </plugin>   
    </plugins>
</build>

Running:

mvn exec:exec

Dependencies:

apt install -y pandoc texmaker
Related