Opening Base64 PDF in new tab with appropriate title/filename.

Requirement: Getting data from an API that gives us the PDF in Base64 format also filename is provided. We need to show this pdf in a new tab so that the user can view and then download it.

Issue: While trying to use the Base64 data to open PDF it does gets opened in new tab but the filename is not proper. Tried it with following JS:

var pdf_newTab ="");


    "<html><head><title>your title in here</title></head><body><iframe title='MY title'  width='100%' height='100%' src='data:application/pdf;base64, " +    encodeURI($parameters.BinaryData) + "'></iframe></body></html>"


The title of the document comes out to be the base64 value we provided. Even tried using blob and data-URL but the title takes the value in the blob or the data-URL

Solution: The solution that I came across was since we have data coming from an external API so we exposed a Get API with the filename as an input param that is also in form of a path parameter
eg: https:<domain>/GetPdf/{filename}
this filename contains the parameter we need to get data from the external API eg: invoice_{prameter} now I am calling the API on button click which internally calls the external get API with the parameters and then returns the PDF data in form of Binary with headers "content-type: application/pdf"

Here we are getting the filename as invoice_2 where 2 is the identifier to be used in the external API.


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