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 = window.open("");
pdf_newTab.document.write(
"<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 parametereg: 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.
can you please elaborate more on code . where we need to add file name (invoice_2). if provide code better to understand
The browser by default automatically asigns the name of PDF from the url. Consider creating an API that takes 2 input parameters one in form of path variable and other in query parameter.
here: File id is the query parameter to filter the file from the table to return the pdf data The filename is path parameter which is dummy variable for the file name to show in new window
One more important thing is that we need to add a header with content type as pdf while returning the data so browser can understand it's a pdfThe documentation for the API looks like: and the sample url can be :
Here MyFile in the url can be anything required important part is the query parameter i.e. the id to filter the PDF from the table