Skip to content

Creating a password-protected PDF document in SAP Integration Suite

Creating a password-protected PDF document in SAP Integration Suite

Hello everyone,

In this blog, I am going to show you how we can create PDF documents in SAP Integration Suite. To generate the PDFs, I’m using a third-party API service called DocRaptor within SAP Integration Suite. For the data source, I’m using the ‘Orders’ entity set from the Northwind service.

The following are some prerequisites required to perform this exercise:

1. SAP BTP Account with SAP Integration Suite service enabled.

2. You need to enable the “Build Integration Scenarios” capability

3. Make sure you can access the “Design” Menu on the left side.

4. Create an account in the DocRaptor website and get the api-key for your account.

5. Create your Gmail-account app password and store those credentials in the security materials.

After confirming all necessary prerequisites are in place, you can begin creating an iFlow within the Integration Suite.

 

Creating a package and iflow

2. Click the “Create” button to create a package, provide all the required information, and then save it.

3.After that, click the “Artifacts” section in this package, then click the “Add” button and select the “Integration Flow” option. Provide all the information for your iFlow.

 

This is the iFlow we are going to create.
Illustration 6: This is the iFlow we are going to create.

Building the iFlow

Add an HTTPS connector by using a connector to connect the sender and start message.

Provide the following data in the HTTPS connector’s connection sub-section:

 

Property Data
Address /testDoc
Authorization User Role
User Role ESBMessaging.send
CSRF Protected Not selected (check box)

By using the HTTPS connector, we can trigger this iFlow from the Postman tool (only when the iFlow is deployed).

 

Now, add a ‘Request-Reply’ palette function to the iFlow and connect it to the Receiver participant using the OData connector.

Here, the Request-Reply pallet function enables synchronous communication with external systems, where an integration flow sends a request, waits for a response, and then processes the reply.
The OData connector facilitates communication with OData APIs, leveraging the OData protocol.

In the OData connector, add the following information:

 

Property Data
Address https://services.odata.org/v4/northwind/northwind.svc/
Proxy Type Internet
Authentication None
Allow chunking Unselect check box
CSRF Protected Unselect check box
Timeout 1
Reuse connection Select check box

 

Property Data
Operation Query(GET)
Resource Path Orders
Query Options $select=OrderID,CustomerID,ShipName,ShipCountry,ShipCity,ShipRegion,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipAddress,ShipPostalCode&$top=500
Attach error details on failure Select check box
Process in pages Unselect check box

 

Once you have filled all the properties in the OData connector, now add an XSLT mapping palette function and connect the Request-Reply to the XSLT palette function.

XSLT (Extensible Stylesheet Language Transformations)
It allows you to convert data between different formats, filter data, and generate complex XML documents.

Now click the highlighted one to create an XSLT document in the iFlow. Once it is opened, add the following content into it:

 

 

Here, we are creating an HTML table inside the XSLT file. The table has CSS inside the <style> tag, column names inside the <th> tags, and row data present inside the <tr> tags. You can also modify the CSS based on your requirement. After that, click the “OK” button. It will go back to the iFlow, and then click the “Save” button to save it.

Now, add a Groovy script to the iFlow and connect the XSLT palette function to the Groovy script.

A Groovy script is a script written in Groovy, a Java-based language, used for dynamic data processing and logic execution. It’s used to perform custom tasks like manipulating payloads, calling external APIs or handling complex transformations not possible with standard mappings.

Now, click the highlighted one to create a Groovy file in the iFlow. Here, we are going to use the third-party API service key, and also we are preparing the payload to send it to that service.

We are using the DocRaptor API service for creating the PDF files.

Here, the htmlContent variable has the previous data, i.e., it has all the information about the orders which is our document content. In the payload, we have test: true; this is mainly for the DocRaptor API service. If we pass test: true, it treats it as a test document. In the DocRaptor API service, we can create a number of test document PDFs. When it comes to production PDFs, it only allows generating 5 PDFs per account.

Now, add one Request-Reply palette function and connect the Groovy script to that palette function in the iFlow.

Add the Receiver participant to the iFlow and then use an HTTPS connector to connect the Receiver and Request-Reply palette function.

In the HTTPS connector, add the following details:

 

Property Data
Address https://api.docraptor.com/docs
Query  (empty)
Proxy Type Internet
Method POST
Authentication None
Timeout 60000
Throw Exception On Failure, Attach error details On Failure Select Checkbox

 

After that, add a Groovy script to format the final payload to send it as a mail attachment.

Now, connect the new Groovy script to the previous Request-Reply palette function.

In the Groovy script, add the following code:


Here, we are taking the data in bytes format and attaching it to the message body. We are also setting the content-type to ‘application/pdf’ in the message headers. After that, click “Apply” button and then click the “Close” button to return to the iFlow. Now, connect this Groovy script to the end message. Add one more receiver participant, connect the receiver to the end message using the connector. Here we will use the Mail connector.

The Mail Adapter enables interaction with email servers, functioning as both a sender and receiver. This allows for sending outgoing emails and retrieving incoming ones.

Add the following details to Mail connector section:

 

Property Data
Address smtp.gmail.com:465
Proxy Type Internet
Timeout 30000
Protection SMTPS
Authentication Encrypted User/Password
Credential Name Use your security material created for your gmail app password
From  Use the same  gmail which is used for gmail app password
To Give the gmail/outlook mail ids (receiver side)
Body Mime-Type Text/Plain
Body Encoding UTF-8

In the mail attachments section, provide the following: 

Click the “Save” button.

Now we need to add the exception subprocess in the iFlow.

Once you have selected the exception subprocess, place it inside the iFlow so that if any error occurs while running the iFlow, it will trigger this exception subprocess.

In the exception subprocess, add a Groovy script with the following code:

Now click “Apply” and “Close” buttons. Click on the “Save” button to save the changes.

Deployment and Testing iFlow using Postman

For deployment, click the “Deploy” button. It will show a pop-up message; click the “Yes” button.

 

Now deployment will start. You can see the status inside the “Deployment status” section.

Click the ‘Navigate to Manage Integration Content’ link. This will open the monitor section.

  • In the endpoints section, locate the generated link. This link is used to trigger the integration flow (iFlow).
  • Copy this link.
  • Use the copied link in a tool like Postman to trigger the iFlow.

We use the OAuth 2.0 type authorization. For that, we need client-username, client-password, and tokenUrl. With that, we can generate the token and pass it to this iFlow link in Postman. Now in Postman, add the iFlow link in the HTTP request and click the “Send” button to trigger the iFlow. You can see the iFlow in the “Monitor Message Processing” tab.

Here, the status is “Completed,” and also we got the email, which has the PDF attachment.

 

Here, the status is “Completed,” and also we got the email, which has the PDF attachment

.Open the attachment; it will ask you for the password to open the PDF. Provide the same password which was given in the DocRaptor payload.

After that, it will open the PDF file. You can see all the orders. 

Please note the watermark currently present is due to the test version being used. This is indicated in the DocRaptor payload by the “test: true” setting. To remove the watermark, simply change this to “test: false.”

 

With the above steps, you can create PDF documents and also you can use the passwords to protect them. 

I hope you found this blog helpful. If you have questions on how Mindset can help you with your SAP BTP and Integration Suite needs, please contact us below!

Interested in learning more?
Visit Mndset’s Linkedin
Visit Mindset’s Blog Library
Visit Mindset’s YouTube Page 

 

Harish Kumar Chendolu has been working in the SAP UI5 space for a little over 2 years now. He is passionate about learning new technologies. When he is not working, you will find Harish either on the cricket pitch or practicing the art of meditation.

Back To Top