Skip to Content
Technical Articles
Author's profile photo Manojkumar Dugyala

Converting any type text file into pdf file

In this scenario I am converting all kinds of files(txt,xml,json etc) into the pdf file.

Step1: Create the Iflow with the desired name.


Step2. Connect the sender and integration process with the HTTP Sender Adapter and give the preferred address.


Step3. Now Upload the itextpdf JAR file which will be used in the groovy script in the iflow by going to references>archive.

Here is the link to download(


Step 4: Create one groovy script and write the below given script.



import java.util.HashMap;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Text;
def Message processData(Message message) {
     def body = message.getBody(java.lang.String) as String;
    OutputStream out = new ByteArrayOutputStream()
    PdfWriter writer = new PdfWriter(out)

	// Creating a PdfDocument object
	PdfDocument pdfDoc = new PdfDocument(writer);

	// Creating a Document object
	Document doc = new Document(pdfDoc);

	// Adding text to the document
	Text text1 = new Text(body);

	// Creating a paragraph 1
	Paragraph para1 = new Paragraph(text1);

	// Adding paragraphs to the document

	// Closing the document
    message.setHeader('Content-Type', 'application/pdf')
    return message


Step5. After writing the groovy script, deploy the iflow and copy the endpoint URL from the SAP CPI Message Monitoring Section.

Step6. To test we can use the Postman Tool.

Here Create the New request with the Endpoint URL and in the Authorization, section use Basic Auth with username and password as Client ID and Client Secret from the BTP Cockpit.

Then in the body change type to binary and upload any kind of your file, after that Click on the send button.


After the completion of the request, we get the below screen, now click on the right side 3 dots, and save the response as file and see the pdf file in the system download location.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Mastan Vali Meduturu
      Mastan Vali Meduturu

      Hi Manoj,

      when I download the jar I am getting only single jar where as I see you have 31 jars.

      also i am getting error when i run the iflow

      script1__Script.groovy: 4: unable to resolve class com.itextpdf.kernel.font.PdfFontFactory @ line 4, column 1. import com.itextpdf.kernel.font.PdfFontFactory;

      Am i missing anything here?



      Author's profile photo Manojkumar Dugyala
      Manojkumar Dugyala
      Blog Post Author

      Hi Mastan Vali,

      yes vali,kernal jar file is missing in your script ,you can download the all the jar files for here (

      Author's profile photo Mastan Vali Meduturu
      Mastan Vali Meduturu

      Hi Manoj,

      its working now, i suggest you update this URL in the blog, as earlier mentioned URL doesn't contain all JARs required to run the iflow.