November 16, 2018

ODT to PDF using XDocReport and Apache Freemarker

XDocreport is an open-source Java library designed to merge and combine templates with a data model. XDocReport supports both Velocity and Freemarker as template engine and allows you to convert the finished document into PDF or XHTML format. Templates are just regular documents, created using Microsoft Word or LibreOffice, with added placeholders for any dynamic content. In this post I show how to merge a data source coming from a simple Java Pojo with an ODT Freemarker template. The finished document will be a PDF file, generated by using the built-in XDocReport converter.

Stack

JDK 1.8
Maven 3.5.9
Opensagres XDocReport 2.0.1
Apache Freemarker 2.3.23

SOURCE CODE (/giuseu/java-utilities)

GIT
git clone https://gitlab.com/giuseppeurso-eu/java-utilities

Customer POJO

 

ODT Freemarker Template

Use LibreOffice Writer to create the ODT template. Input fields are defined according to the Freemarker syntax.

XDocReport Engine

Main Executor

 

 

Related posts

5 Comments

  1. Pedro

    This dependency does not execute my code. When I remove it works only there problems in the conversion of the document.

    fr.opensagres.xdocreport
    fr.opensagres.xdocreport.converter.odt.odfdom
    2.0.0

    Reply
    1. Giuseppe

      Hi,
      according to the provided stack, the code works correctly. On a fresh build:

      > git clone https://gitlab.com/giuseppeurso-eu/java-utilities

      > cd java-utilities/3rdpartyapi

      > mvn clean install
      ...
      BUILD SUCCESS
      ...
      > mvn dependency:tree | grep opensagres.xdocreport.converter.odt.odfdom

      fr.opensagres.xdocreport.converter.odt.odfdom:jar:2.0.1:compile

      What is exactly your issue?

Leave a Reply

Your email address will not be published.