Creating PDF's With Custom Data Using Mule 4+ Java

DZone 's Guide to

Creating PDF's With Custom Data Using Mule 4+ Java

While there's no way to generate a PDF in Mule Application, Mule allow you to write a Java code and make use of it in your API.

· Integration Zone ·
Free Resource

Hello, readers!

We know that we can create PDFs and Images using Base64 Data, we can generate PDFs only if we have a valid Base64 content which includes, PDF format like Borders, Fonts, Style along with Data. Even if a small character is missed in Base64 content, you won't be able to generate a PDF.

In short, you should have a valid base64 to generate PDFs using Mule 4.

There's no option to generate a PDF by providing Custom Data as input in Mule Application.

But still, Mule helps you to allow you to write a Java code and make use of it in your API.


  • We need an external Jar: iTextPdf
  • Custom Java Code
  • Java connector to invoke Java class

Step One

Add below dependency into your pom before writing your Java code. So that you can import the classes while writing Java code




Step Two

Create a Package under src/main/java and create a Class. Please note that you have to be familiar with Java code. Make sure your code is good enough to have the necessary Structure of PDF like borders, paragraphs, Font Style, etc.

If you are not familiar, no worries, am providing you the Git repo link where I have written a sample code that helps you to dig further and modify your code accordingly.

Step Three

Now use Java connector (Invoke Static ) and provide your class name and method name with appropriate arguments to be passed fo the method you have written.

Note: Methods and arguments are displayed automatically if your Java class is under src/main/java

invoke status

Step Four

You can pass inputs from POST body like name, role and transform your message accordingly and pass them as arguments to your Java method so that you can create a Custome PDF file.


If you can see the PDF which is generated, I have used Name and role in it.

creating PDF

That's pretty simple, isn’t it?

Why don’t you try out!

Find the code here: https://github.com/sravanl/generatePdfs

Note: Please change your FILE path that is mentioned in Java code to your local path

As said, you can modify according to your need!

custom data, integration, java code, mule 4, mulesoft, mulesoft 4, tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}