Scroll to top

How to Download a PDF from Base64 String in VBCS


Roshan - July 8, 2022

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

Roshan

Roshan Baig is renowned for his strategic acumen and hands-on delivery and project leadership. His expertise spans application development, integration, and team management, honed through extensive experience across the GCC, US, Australia, and APAC regions. Roshan's global perspective and cultural agility, combined with his association with Conneqtion—an Oracle Cloud Infrastructure (OCI) & Oracle SaaS Implementation Partner have been instrumental in driving successful projects, enabling seamless digital transformation, and facilitating cross-border collaboration.

Author avatar

Roshan

Roshan Baig is renowned for his strategic acumen and hands-on delivery and project leadership. His expertise spans application development, integration, and team management, honed through extensive experience across the GCC, US, Australia, and APAC regions. Roshan's global perspective and cultural agility, combined with his association with Conneqtion—an Oracle Cloud Infrastructure (OCI) & Oracle SaaS Implementation Partner have been instrumental in driving successful projects, enabling seamless digital transformation, and facilitating cross-border collaboration.

Related posts

2 comments

  1. Shahzad

    I am using the same approach for calling the BIP report from vbcs application but every time error is comming like the string need to be decoded is not in correct encode format. Can you please guide me or share some sample document or application which you have developed.

    • Karan Tulsani

      Hi Shahzad,

      What is the report format which you’re calling from OIC? Is it in pdf or any other format?

      If the report format is not pdf then this method is not suitable.

      Thanks.

Post a Comment

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