Recently, I came across a blog written by Sharadha Krishnamoorthy entitled ‘Generate PDFs in the cloud – SAP Forms by Adobe’ and found it very interesting. This blog was very informative, providing an end-to-end steps to generate a PDF document by harnessing the Adobe REST API on SAP Cloud Platform. Given that I have a little experience in PHP programming, I followed the same approach guided by Sharadha and added some spices into the experiment.
For my experiment, I would generate and view the PDF document directly via a web browser. Since this approach requires a direct call to a URL, I uploaded the template file (.XDP) and the data xml file onto a web server. Then, I wrote a PHP script to perform all the necessary tasks to render the PDF document on the web browser.
Below are the documented steps on how this was done.
Step 1: Create the template file and data xml using Adobe LifeCycle Designer. Refer link.
In my case, I have named my files f1.xdp and f1_data.xml respectively.
Step 3: Write a PHP script. Save the file name as restClient.php.
This script consists of two main processes. One is to retrieve the OAuth token and two, calling the Rest API on SAP Cloud Platform to render the PDF document onto the web browser.
Step 4: Call the PHP script via the web browser.
Let’s take a look at the restClient.php script chunks and their purposes.
The header function is used to tell the browser that it should be expecting a PDF document for display
The main processing starts by calling the callService function. This function consists of two main processes. The first process is to retrieve the OAuth token from SAP Cloud Platform by calling the function getoauthToken(). The second process is to render the PDF document by calling the SAP Cloud Adobe REST API, passing the API with base 64 encoded template file and data xml file. (f1.xdp and f1_data.xml, in my case)
Finally, to view the PDF. Just enter the URL on the browser.
The source code of restClient.php can be downloaded from my github repository at https://github.com/singloob/Web/blob/master/restClient.php
To wrap things up, what I gather from this experiment is that SAP Cloud Platform Forms by Adobe’s REST API is indeed a convenient way to render PDF documents, especially on the web.
Lastly, your feedback or questions are most welcomed.