Templ4docx 2.0.0 - Table Variables

In this post I would like to spend some time on Table Variables. The TableVariable is perfect solution when you have n-records of the same variable. Lets consider the following case: we have docx document with table which consists of four columns: Name, Age, Image and list of languages. Our goal is fill the table with students’ data. For this purpose I’ve created the following docx template:

read more

Spring Boot - Security in distributed system

Spring Security is indispensable part of every enterprise Spring based application. Everything looks pretty easy, when you want to secure single web-application. Unfortunately, everything looks completely different when your system consists of many components. In that cases the expected behavior is single login for whole system, not separate login for each web-services. Suppose, you have two RESTful web-services. Application should allow a user to login, receive session token and give access to resources of both services using the token. At this point we come across the first problem. Spring does not support authentication by JSON object out of the box. In order to send credentials as json object, we have to write some handlers. But let’s start from the beginning.

read more

Templ4docx 2.0.0 - Image Variables

In the previous post, I’ve written about simple text variable. Now, I would like to spend some time on Image Variables. In the previous example, we created an invitation. Now I’m going to change a little our example, and we will create a business card. The standard card has information about name, last name and phone number. I would like to add image to my business card as well. So in my business card will be 4 variables: ${firstname}, ${lastname}, ${phone}, ${photo}. The first three are simple text variables. The last one is variable of image type, so we need to create appropriate ImageVariable object. In my case, I want to insert photo 75px x 75px to business card template: new ImageVariable("${photo}", "E:\\photo.jpeg", ImageType. JPEG, 75, 75)

read more

Templ4docx 2.0.0 - Text Variables

The most common situation is when we want to replace simple text variable. Imagine that you have an invitation template and you want to prepare filled invitation with firstname and lastname. So the only thing you need is to find variables in the template and then replace them with the correct values. Suppose that the variables in the template are as follows: ${firstname} and ${lastname}. This pattern of variables is the default one for templ4docx and does not require to define it. However, if the variables in the template have a different form, for example: #{firstname}, you must tell to templ4docx how they look like. In this case you must define the object VariablePattern in the following way new VariablePattern("#{", "}") and then set it to Docx object:

read more

Templ4docx - Easy way to fill docx templates

A few days ago, I had to prepare Proof-of-Concept connected with filling templates prepared in docx. I took into account two libraries: org.docx4j and apache-poi. After a short play with them, the second library appears to be more suitable in my case. In order to compare these two libraries I’ve prepared two classes that perform the same operations:

read more


Łukasz Stypka

Java experienced enthusiast, opened for new technologies. Clean code and simple solution fan.

Tomasz Kuryłek

Self-styled and passionate java hipster. Focused on solution that makes user and himself ecstatic..