How to convert a renderID of a PDF to a JPEG or PNG?

I have generated a PDF from a third-party API which returns me with a renderID as shown here:

I am trying to pass this PDF into the Stripe API for updating a product in the 'images' field:

Stripe API Reference - Update a product

The problem I am running into is that the Stripe API only accepts JPEGS/PNGS so I somehow need to convert my PDF to one of these formats to pass it into the API.

Hello! I’m not sure if we have this capability built-in to Retool, but perhaps there’s a JS library we can import and use.

See the “Custom JavaScript Libraries + NPM modules” section here:

https://docs.retool.com/docs/custom-js-code

This guide seems to indicate that PDF -> JPG might be possible using the PDF.JS library, but I haven’t been able to get PDF.JS to work in Retool.

There are also seem to be a few APIs that can do this conversation, but again, I haven’t been able to get them to work in Retool.

Do you know if Base64 is accepted by the endpoint you’d like to use?

Hi, thank you for the response.

Unfortunately, Base64 is not accepted in this API. The accepted format is a "URL in the form of either a JPEG or PNG.

I'll look into the libraries and attempt to find a compromise.

That seems like your best bet! I double checked with my team today and pdf to jpeg don’t seem to be supported in Retool natively :pensive:

Let me know if I can help with anything else though, hopefully with a better resolution!

When did PDF to jpeg supported in Retool natively?

Hey @afaq_mehmood! Are you asking about timelines for rendering a PDF to/from JPEG in Retool?

Yes

Got it, thank you. It’s not on our current roadmap, but we’ll keep you updated in this thread! :+1:

2 Likes

@victoria Maybe it make sense to add this to the roadmap again. Especially in the context of ChatGPT. Here i can only analyse images and not pdfs. So i need to convert the pdf to an image.... Is this intended

1 Like

@victoria I think the easiest fix is adding more libraries to Javascript and Python so i can convert the pdf to an image. After a day trying I did not found any library which would allow me to do this.
But maybe I am wrong please correct me here. Community I would appreciate your help :grinning:

@victoria I hope you find time soon to give us/me a feedback. Because I am currently messing around with retool to understand its capabilities. This would small feature would have a huge impact on our operations and this would be a strong Yes for retool. Who anyways wants to copy paste information out of a pdf manually :grinning: ? With the conversation I could ask Chatgpt to do this for me :grinning:

Hey @Gian-Luca_Muschong, thanks for the bump here. I've added your +1 to the internal ticket tracking this. As @victoria mentioned this feature request is not going to be prioritized near-term, but we'll update this topic when there is any movement.

1 Like

I was able to get this to work with convertAPI (see here ) - query5 is a POST request to https://v2.convertapi.com/convert/pdf/to/jpg with a generic token (you'd need to create your own) which includes the PDF base64 and returns a jpeg file.

{
  "request": {
    "url": "https://v2.convertapi.com/convert/pdf/to/jpg",
    "method": "POST",
    "body": {
      "Parameters": [
        {
          "Name": "File",
          "FileValue": {
            "Name": "my_file.pdf",
            "Data": "<Your PDF Base64 string>"
          }
        }
      ]
    },
    "headers": {
      "User-Agent": "Retool/2.0 (+https://docs.tryretool.com/docs/apis)",
      "Authorization": "---sanitized---",
      "Content-Type": "application/json",
      "X-Retool-Forwarded-For": "10.60.24.168"
    }
  }
}

I can now use this jpeg a Retool image component
image
(docs here)

1 Like