Boomi

XML To PDF Conversion

In this blog, we will develop a process which will convert XML into PDF in Dell Boomi.

Boomi does not support PDF conversion directly, but we can do it by importing PDF libraries and using custom scripting to convert documents into PDF Format.

First, let us see how to import PDF Libraries and deploy them to the atom. In this Use Case, we are importing two PDF libraries i.e. Apache PDFBox and iText.

Step 1: To import the Apache PDFBox library, go to https://pdfbox.apache.org/ > Download and choose the jar as shown. The jar gets downloaded.

Step 2: To import the iText library, go to https://jardownload.com/artifacts/com.itextpdf/itextpdf/5.5.9/source-code and choose the jar as shown. Once we choose it, the jar gets downloaded.

Now, we will upload the downloaded jar files in the Account Library to the Boomi Account.

Step 1: Log on to the Boomi platform (https://platform.boomi.com/) with the required credentials i.e. Email Address and Password.

Step 2: Once logged into the Boomi platform, we will be able to view the Home page.

Step 3: Go to Settings > Account Information and Setup > Account Libraries and upload the jar files which we have downloaded by choosing Upload a File.

Step 4: Now, create a custom library component and add the uploaded JAR files in the account library to the component. Navigate to the Build tab and click on New as shown.

Step 5: Choose Type as Custom Library. Component Name and Folder can be given based on your choice. Click on Create.

                                

                                                 

Step 6: Choose Custom Library Type as Scripting from the drop down and these jars will be available for scripting.

                                          

  • Select Jars which we have uploaded in Account Library. Click save.

                                            

Step 7: Deploy the Custom Library component to an atom because these are not explicitly referenced by a process or any other component, we must deploy them independently. Click on Create Packaged Component.

Step 8: The process gets selected automatically. Click Add Details.

  • Next, select the version and write notes if you have any. Click on Create Packaged Component.

  • Now, we see that the package has been created successfully and click on deploy.

  • We will then have to select the environment. Choose production and click select version and review.

  • We will be asked to cross-check the environment which we have configured in the deployment tab.

  • Once, we click on deploy we will be able to see that deployment is done successfully. Click save and close.

Now, we will create a process which reads JSON data from the Disk directory and converts it into XML. Then, XML data will be covered in PDF Format using scripting.

Step 9: Click on New to create a process. we will be able to see three fields i.e. Type, Component Name and Folder.

                            

  • Select Type as process as we are building a process. Component Name and Folder can be given based on your choice (i.e. which name to be given and where do we want to create the process). Click on Create.

Step 10: We see that the process gets created with a start shape which is configured with AS2 Shared Server by default.

Step 11: Select the start shape and choose No Data. Click ok.

                                   

Step 12: Drag and drop the disk connector shape onto the process canvas to read a file from a specific directory.

  • We have to configure 3 fields in connector i.e. Action, Connector and Operation.

  • We see 2 actions i.e. Get and Send in Actions.

Get – To get the data from a disk location.

Send – To send to the disk location.

  • Here, we will choose action as GET as we are reading the file.

  • Click + on connection to create a new one.

  • Name the file and give the directory from where we want to read the file. Here, we are reading JSON files from D drive and Boomi Examples folder as shown in the screenshot.

  • Click save and close
  • Now, we will configure the operation. Click + on operation to create a new one.

  • Name the operation and configure the following.

  • File Filter: Read-only files with a file name that matches the file filter. Here, it will be Acc.json

File Matching Type:

  • Wildcards uses simple file filters like * and. * represent multiple characters and ? represents a single character.
  • Regular Expressions can include complex regular expressions.
  • Exact Match includes the filename that we are reading.

  • Here, the file matching type would be Exact Match as we are giving the file name.

  • Maximum files to read: It sets the maximum number of files to be read at one time. Let it be default.
  • Delete files after reading: If we want the file to be read and deleted, we can check this option. Here, we are leaving it to default. Click save and close
  • The complete disk operation looks like this,

Step 13: Drag and drop the Map shape onto the process canvas. Click + and Name the map.

                                

  • Add source side and Destination side profiles to the map. Here, the source side would be the JSON profile and the Destination side would be the XML profile. First, we will add a Source profile. Click choose and select the folder where we saved the profile.

                       

  • Here, the Profile Type will be JSON and click on Create New Profile.

  • Name the profile and click on import.  In this example, we used the below file as an input.

  • Choose the file from the directory where we have saved the file. Click on Next.

  • We see that the profile is imported.

Step 14: Now, add the destination profile. Click choose on the right side as shown.

  • Select Profile Type as XML and click on Create New Profile.

  • Name the profile and click on import. In this example, we used the below file as an input.

  • Choose a file from the directory where we saved it. Click Next.

  • We see that the profile has been imported. Click finish, save and close.

  • We see that source and destination profiles have been imported. Provide one-to-one mapping from source to destination. Click save and close.

Step 15: To write a Groovy Script, drag and drop the data process shape onto the process canvas and click on + as shown.

                                                 

  • Choose Process Type as custom scripting from the drop-down. Click on edit.

Step 16: We will be able to see the command prompt as shown in the screenshot.

                 

Step 17: Now, we will write a groovy script to convert XML into PDF Format as shown below.

  • Add the below script in the command prompt and click OK.

import java.util.Properties;

import java.io.InputStream;

import java.io.FileOutputStream;

import com.itextpdf.text.Document;

import com.itextpdf.text.Paragraph;

import com.itextpdf.text.pdf.PdfWriter;

for( int i = 0; i < data context.getDataCount(); i++ )

{

InputStream is = dataContext.getStream(i);

Properties props = dataContext.getProperties(i);

String Data = is.text;

OutputStream file = new FileOutputStream(new File(“D:/BoomiExamples”,”sample.pdf”));

Document document = new Document();

PdfWriter.getInstance(document, file);

document.open();

document.add(new Paragraph(Data));

// document.add(new Paragraph(is.toString()));

document.close();

file.close();

}

Step 18: Drag and drop the stop shape onto the process canvas to indicate the end of the flow.

Step 19: Arrange all the shapes in order and test them by configuring the local atom as shown below.

Step 20: We see that the process has been executed. Click on view source to see the output.

  • Once, we open the document, it looks like

Step 21: Navigate to the “D:/BoomiExamples” folder and we see that a file has been created with the name “sample” in pdf format.

Author

TGH Software Solutions Pvt. Ltd.

Leave a comment

Your email address will not be published. Required fields are marked *