Skip to main content
Integration Suite

Creating a password-protected PDF document in SAP Integration Suite

HC Harish Kumar Chendolu, Harish Kumar Chendolu has been working 8 min read

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

    Integration Suite Capabilities section with the Build Integration Scenarios card outlined in red

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

    Integration Suite home page with a red arrow pointing to the Design menu in the left navigation

  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

Design page listing integration packages, with a red arrow pointing to the Create button

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

New Package header form with Name, Technical Name, Short Description, Version and Vendor fields

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.

Add menu in the package Artifacts tab with the Integration Flow option highlighted

Finished iFlow: HTTPS sender, Northwind OData call, XSLT mapping, scripts, DocRaptor HTTP call, Mail receiver
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.

iFlow editor with a red arrow at the HTTPS connector between the Sender and the Start event

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).

HTTPS connector Connection tab with Address /testDoc, User Role authorization and ESBMessaging.send

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

Get data from Northwind step connected to a Receiver by an OData connector

Here, the Request-Reply palette 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:

OData connector Connection tab with the Northwind service address, Internet proxy and no authentication

OData connector Processing tab with Query(GET) on the Orders resource path and a $select query

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.

Get data from Northwind connected to an XSLT Mapping step, with the create-resource icon highlighted

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:

XSLT code, part 1: stylesheet header, output method html, and CSS for the table inside the style tag

XSLT code, part 2: rest of the CSS, Sales Orders Report heading, th column names and the for-each over orders

XSLT code, part 3: td value-of cells for each order field and the closing tags

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.

XSLT Mapping connected to a Groovy script step named preparing the payload, with the create icon highlighted
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.

Groovy code building the DocRaptor payload: API key, test flag, document content and encryption password options

End of the Groovy script: landscape option, Content-Type application/json header, and payload set as body

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.

Preparing the payload script connected to a get data from docraptor step with an HTTP connector

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

Get data from docraptor step connected to Receiver1 by an HTTP connector

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.

Get data from docraptor connected to a preparing final data script step, followed by the End event

In the Groovy script, add the following code:

Groovy code that reads the body as bytes, sets it as the body and sets Content-Type to application/pdf

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.

End event connected to Receiver2 by a 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:

Mail connector Processing tab with mail body text and an invoice.pdf attachment taken from the message body

Click the “Save” button.

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

Process menu in the iFlow toolbar with a red arrow pointing to Exception Subprocess

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:

Groovy code that reads CamelExceptionCaught and adds the exception message to the message log as an attachment

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.

iFlow editor with the Deploy confirmation dialog, Cloud Integration runtime profile and an arrow at Yes

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

Deployment Status tab showing Deployed, runtime status Started and a Navigate to Manage Integration Content link

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.

Monitor Message Processing showing one message for the Test IFLOW_using_docraptor artifact with status Completed

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

Monitor Message Processing showing one message for the Test IFLOW_using_docraptor artifact with status Completed

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

Email inbox with an Orders pdf from cpi message and its invoice.pdf attachment outlined in red

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.

invoice.pdf preview showing an Enter a password dialog for the password-protected file

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

Opened PDF Sales Orders Report table of Northwind orders with a TEST DOCUMENT watermark across the top

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.”

Opened PDF Sales Orders Report table of Northwind orders without the test watermark

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 Mindset’s Linkedin
Visit Mindset’s Blog Library
Visit Mindset’s YouTube Page

Share