24
Views
4
Comments
Open pdf or image based on file format in new tab instead of downloading
Discussion

Hi,

I have my file which contains some sensitive data, and I want to open this file in a new tab based on certain parameters. How can I do this? 



2026-01-15 03-18-59
Vijay Malviya

Hi @Sanjay Sharma 

You can implement this logic using JavaScript or a server action in Reactive or ODC. I will provide a simple example of JavaScript code that will let you achieve this efficiently.


First of all, you should use the Binarydata extension to convert your binary data to Base64.

For Reactive or ODC, you can create a client action for this.

Client Action-

Javscript-

(() => {   

    const fileName = $parameters.FileName;

    const base64Data = $parameters.Base64Data;  

    const ext = fileName.split('.').pop().toLowerCase();

   debugger;

    const data = base64Data.startsWith('data:') ? base64Data.split(',')[1] : base64Data;

    const mimeTypes = {

        jpg: "image/jpeg",

        jpeg: "image/jpeg",

        png: "image/png",

        pdf: "application/pdf"

    };

 

    const blob = new Blob(

        [Uint8Array.from(atob(data), c => c.charCodeAt(0))],

        { type: mimeTypes[ext] || "application/octet-stream" }

    );

  

    window.open(URL.createObjectURL(blob), "_blank");

})();

Hope this Help.

Thanks

Vijay M.


2025-10-05 04-46-19
Sanjay Sharma

Thanks @Vijay Malviya 

It's working fine for me.

2023-10-16 05-50-48
Shingo Lam

Please mark @Vijay Malviya comment as solution. Then the status of this topic will be Solved, the others won't come to investigate it anymore

2025-12-03 17-22-41
Lavanya Kamalaguru

Hi @Sanjay Sharma,

Please check out the below module. I have implemented the same.

PDF.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.