Creating PDF's with Custom Data using Mule 4+  Java

Creating PDF's with Custom Data using Mule 4+ Java

Hello Muleys,

If you have remembered my previous article on Creating PDFs and Images using Base64 Data, you can generate PDFs only if you 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 that we can 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.

Requirements :

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

Step 1 :

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

<dependency>

    <groupId>com.itextpdf</groupId>

    <artifactId>itextpdf</artifactId>

    <version>5.5.13.1</version>


</dependency>

Step 2 :

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 which helps you to dig further and modify your code accordingly .

Step 3 :

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

No alt text provided for this image

Step 4 :

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.


No alt text provided for this image

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

No alt text provided for this image


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!


Happy Learning ,
Yours
Sravan Lingam










Neha Chopra

Application Integration Consultant | Dell Boomi | MuleSoft | Oracle SOA Suite | OIC | SOA

4 年

This is nice... pretty simple????

Silvio Silva

Integration Architect | 1xMulesoft Certified | AWS | Azure | 1xSOA Certified | DevOps | Helping the best professionals with knowledge in Mulesoft/AWS and Azure connect with leading IT companies in Brazil and Portugal.

4 年

I liked. Simple and objective !!

Eswara Pendli

Senior MuleSoft Consultant | MuleSoft Mentor | 7xMuleSoft Certified | Trailhead Adventurer

4 年

Nice one ??

要查看或添加评论,请登录

Sravan Lingam的更多文章

社区洞察

其他会员也浏览了