Issues encoding PDF contents into base64 to display in PDF component

I'm getting PDF contents using the Salesforce API and trying to display it in a PDF container.

This is how the result appears from the API call to get content version data from Salesforce:
image

I first tried to encode the results into base64 directly in the PDF source input, but recieved this error around special characters:
image

I then tried this function to remove the special characters, and the encoded string appears, the but the PDF still won't display:

Any advice on how to display it would greatly appreciated!

1 Like

Hello @nicole

I am using Retool PDF component that display data, and it's working perfectly. However, I believe there is an issue with retrieving data from your API.

image

1 Like

Hi @nicole - welcome to the community! :slightly_smiling_face:

I'm fairly sure that the Salesforce API is streaming the PDF data back to you in a fashion similar to what is described here, meaning you have just one part of the file. The solution likely involves awaiting the result of your query in order to ensure that you have the entire document prior to converting it!

1 Like

Hi Darren - Appreciate the response! Any ideas on how to do that? I've tried a few different things online using a transformer or JS query without luck

I can try to put together an example! Are you currently using the built-in Salesforce resource or a generic REST API query?

That'd be amazing! I actually have both working - the built-in Salesforce connector using the CRUD Action type to retrieve content version details, and the REST API connection using the endpoint services/data/v61.0/sobjects/ContentVersion/XXX/VersionData

Both are returning the same response. Let me know if there's anything else I can provide. Thanks!

It has actually been surprisingly difficult to get this working! After digging into it more, I don't think the issue is asynchronicity - the Salesforce API is just returning a raw text representation of the PDF file. The following is the closest I got to processing the response and getting it to display within Retool:

The result is a correctly-formatted PDF, but it's missing content. I haven't pursued this as the authorization would be kind of a pain, but my most recent idea is to write a fetch request as a raw JS query in order to handle the result as an arraybuffer.