Insert image into a Google Document

Hi Community!

This is my case. I’m creating a document (Google Document) from template that has {{xyz}} tags to be replaced with some info I’m getting in a previous step.

image

The output from the document creation is a pdf format, so looking into it, I see that it has rendered the URL instead the image:


(this was using GDrive URL but it happens equal with a direct .png URL as stated before).

How can I achieve this?.

Thank you,
Diego

Hello! Could you share what the overall task is? I’d be happy to help!

So, do you need to update one image in the document or several? How many placeholders are there?

By default, we don’t have a function for replacing images based on placeholders, but this can easily be implemented using JavaScript.

Please share the details of your idea, and we’d be glad to assist you!

Hi Rian, thank you for your reply.

At the end, I solved this by myself. This is what I did:

After the doc creation, I got all the images I created using the id from each one of them (when the images are created are saved in GDrive), and created a batchUpdate json to patch the created document. To do the patch correctly, I got all the placeholders where the images are supposed to be, to get the index for each one, and lastly I run the batchUpdate instruction to put the images replacing the placeholders.

1 Like

Great job! Thank you for sharing your success!

I believe your solution will definitely help many people in the future.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.