Unable to generate word doc with image

Raj40
Tera Contributor

Hello All,

 

I am generating word doc dynamically with some content and image, but image does not render. Any ideas or is there a work around for this ?

 

Raj40_0-1683121776779.png

 

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @Raj40,

 

Follow the below steps:

1) Convert your image to base64 using CONVERT YOUR IMAGES TO BASE64

2) Create a system property with string type.

3) Store the base64 image code in it.

4) In widget server side scripts call system property as

 

data.yourImage = gs.getProperty("company.name.logo");

 

5) Use the data.yourImage variable in image tags as

body = body + '<img src="'+ c.data.yourImage + '" width="189" height="47"/>';

 

Thanks,

Sagar Pagar

The world works with ServiceNow

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Raj40 Looks like you need to write the base64 encoded form of the inline image within the word document. Here is a reference from the Microsoft to write an inline image within a word document https://learn.microsoft.com/en-us/javascript/api/word/word.inlinepicture?view=word-js-preview

 

Hope this helps.

Sagar Pagar
Tera Patron

Hi @Raj40,

 

Follow the below steps:

1) Convert your image to base64 using CONVERT YOUR IMAGES TO BASE64

2) Create a system property with string type.

3) Store the base64 image code in it.

4) In widget server side scripts call system property as

 

data.yourImage = gs.getProperty("company.name.logo");

 

5) Use the data.yourImage variable in image tags as

body = body + '<img src="'+ c.data.yourImage + '" width="189" height="47"/>';

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Abhijeet0610
Tera Contributor

can you please tell me the way to create a word document dynamically .