DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Jakarta EE 12: Entering the Data Age of Enterprise Java
  • Building Realistic Test Data in Java: A Hands-On Guide for Developers
  • How to Convert Between PDF and TIFF in Java
  • Java UDFs and Stored Procedures for Data Engineers: A Hands-On Guide

Trending

  • Why Your DLP Policies Fall Short the Moment AI Agents Enter the Picture
  • AI Paradigm Shift: Analytics Without SQL
  • MuleSoft IDP: Enhancing Efficiency and Accuracy in Data Extraction
  • Feature Flag Debt: Performance Impact in Enterprise Applications
  1. DZone
  2. Data Engineering
  3. Data
  4. Creating PDF's With Custom Data Using Mule 4+ Java

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.

By 
Sravan Lingam user avatar
Sravan Lingam
·
Jul. 23, 20 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
14.2K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Requirements

  • 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

Java
 




x


 
1
<dependency>
2
    <groupId>com.itextpdf</groupId>
3
    <artifactId>itextpdf</artifactId>
4
    <version>5.5.13.1</version>
5
</dependency>



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.

CreatePDF

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!

Java (programming language) PDF Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Jakarta EE 12: Entering the Data Age of Enterprise Java
  • Building Realistic Test Data in Java: A Hands-On Guide for Developers
  • How to Convert Between PDF and TIFF in Java
  • Java UDFs and Stored Procedures for Data Engineers: A Hands-On Guide

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook