How do I trouble shoot why a PDF won't display?

I have an API endpoint that returns base64 encoded data. Other questions posted here indicate that making a rest api call, and having the pdf component consume the resulting data is the way to go. Unfortunately, even though the app I want to replace with Retool can consume this data, and parsing it with various online tools works fine also, Retool only gives me one of two errors:

If I set the PDF control to consume just data.base64Data, I get "No PDF File specified", if I use the entire json returned from the API. I get "PDF cannot be loaded".

Incidentally, the json the rest call I use returns is typically like this:

{"name": "letter",
"type": "application/pdf",
"sizeBytes": 27148,
"base64Data": (long base64 string that I'm not even allowed to upload separately, so use your imagination)
}

I've tried a bunch of variations for setting this that I've seen in other posts, and am at the point where I think it must be something about the PDFs I generate. Is there some way I can get a better sense of what's going on in the PDF component when it sees an error, on the off chance I can change things in the its API, as opposed to giving up on using Retool for this?

Hi @Richard_Elam :wave:

Welcome to the community! It looks like you're well on your way to displaying the PDF.

To start troubleshooting, I recommend first pasting the base64 string directly into the PDF component's File URL field.

If that doesn't work, it's likely that the PDF isn't correctly encoded in base64.

Should the PDF display correctly, you can proceed to link the output of your query. For instance, if your query is named getPDF, you would use {{ getPDF.data.base64Data }} in the PDF component's File URL field.

Does that work for you?

That is a big help. I wouldn't have thought of pasting the text directly into the url field, but it does display the pdf. I can figure out what's goin on from there. Thanks.

1 Like

So, it looks like the base64 PDF data I get back from calling the api directly is different than what I am getting through retool. I was barking up the wrong tree completely.

... it looks like my base64 encoded pdf data was encoded again when returned through Retool, and I just had to decode. Thanks again for getting me on the right track.

1 Like

You're welcome @Richard_Elam!

Feel free to mark my first comment as a solution, so it might help other in the future.