Scroll to top
Please assign a menu to the primary menu location

How to Download a PDF from Base64 String in VBCS


Roshan - July 8, 2022 - 0 comments

Reading Time: 3 minutes

In this post, we will try to understand the need to download a PDF file from the backend in a single click in VBCS. Let us go through the Problem first and then we will cover the Solution and Conneqtion Approach.

The Problem

Saving a PDF file as base64 in the backend will be a random combination of numbers and letters. Now, what if the user wants to download the same PDF file from the backend on a click of a button in VBCS.

download pdf file in VBCS

The Solution

Assuming there is already some kind of a  ‘Download’ button that fires an API request when clicked on, which returns the response in bas64 format. Then, using the small JavaScript code we can achieve this functionality.

Conneqtion Approach

Step 1: Open VBCS Application in Development Mode.

Step 2: Configure the REST API which returns the base64 as response in the connection.

Step 3: Add below piece of JavaScript code in the PageModule function.

JavaScript code in PageModule

JavaScript code in PageModule

The code above is pretty self-explanatory but we will try to simplify it for you with a tiny explanation.

The JavaScript code creates an anchor tag element assigned to the constant download-Link , uses the base64 pdf along with “octet/stream” as a href attribute, adds a download attribute with the name of the file. Then clicks on the created link to download the pdf. It’s that simple.

Step 4: Create a new button event – ojAction and configure the action items as shown in the screenshot below

ojAction button event

Step 5: Assign Input parameter to the repairBase64 function.

assign input paramter in base64

Step 6:  Assign input parameter to the downloadByteFile function

1) Data will be output of repairBase64 functional.

2) name will be file name.

assign input parameters

 

Result

pdf from base64 string

pdf from base64 string

Author avatar

Roshan

Roshan comes with an extensive experience in the Oracle Implementation domain after completing his Electronics and Communication Engineering from Bengaluru. He holds a plethora of professional certifications from Oracle after starting as an Associate Developer role and quickly made his way to a Senior Manager. He has worked with clients across the globe in ANZ, EMEA, APAC and Europe. At Conneqtion Group, Roshan has been a key part of managing the organization’s largest risk teams apart from sharing his experience and skills to develop and nurture young talent with his dynamic vision.   

Related posts

Post a Comment

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