can I display an image on MS word with document template ?

Posted by Jirawat Suramart on 07-Jul-2016 23:36

I need to display an image on MS word with document template.
I've try to use image token from hosted file (#url and nothing) but that doesn't work.
so that MS Word file display to string. even I have try to build a formula field then storage HTML code of image but that doesn't work too.
so I used to success this in rollbase "v.3" but not now.
sorry about my weak Enlish and Thank you for answer.

All Replies

Posted by Shiva Duriseati on 08-Jul-2016 02:33

Hi Jirawat,

Please create a field of type "Template Field" (ex:TemplateField)and from the token helpers, select the image which you have uploaded in hosted files and copy the image tag and paste it in template field section.

Ex: <img src='{!#HOSTED_FILE.qkAtE82oQyu17TI0PdtxaQ#url}' border='0' align='absmiddle'/>

After creating template field use this token (ex: {!templatefiled}) either in HTML or WORD doc templates.I've verified with HTML template and its working fine.

Please revert back incase you need further assistance.

Regards,

Shiva

Posted by murali on 08-Jul-2016 09:48
Siva, if I open that word file in a machine without internet access, will it still display the image?
Posted by Jirawat Suramart on 11-Jul-2016 22:54

Shiva, Thank you for answer bro. I've attempted to do that solution for many time, So that working fine in PDF and HTML Template but doesn't in DOC. How can I do more for serve this problem?

Posted by Shiva Duriseati on 12-Jul-2016 01:46

Hi Jirawat,

I am looking into it will provide an update very soon.

@Murali Yes the solution which I have provided earlier will not have any effect even without internet access.

Regards,

Shiva

Posted by Shiva Duriseati on 12-Jul-2016 09:34

Hi Jirawat,

You are on Private or Public Cloud?

Regards,

Shiva

Posted by Jirawat Suramart on 12-Jul-2016 21:18

Hi Shiva,

I'm on private rollbase v.4.0.6.3

Thank you guy.

Posted by Shiva Duriseati on 13-Jul-2016 01:06

Hi Jirawat,

Currently Rollbase support inserting image into DOC only through "image upload" field. Since your are getting image from hostedfile you were not able to insert into DOC.

I have created a defect #46595 for this and will let you know ETA very soon.

However since you are on Private Cloud ,you can add java classes to be exposed to Rollbase javascript. Util the fix is available you can make use of the below workaround.

Steps:

1)Convert the HostedFileImage to ImageUploadField.

2)For the above operation there is a server side API called "rbv_api.setBinaryFieldValue()".

In the above step we need to pass base 64 encoded value of image as one of the parameter. But using pure js encoded value cannot be generated,but with help of java classes this can be be done.

(In Rollbase Private Cloud java classes can be added and later can be exposed to Rollbase javascript).

3)Once you have the encoded value which is generated from above step you can directly call "rbv_api.setBinaryFieldValue()" to convert hostedfile to image upload field.

4)Run the document template(which should be using image upload field token).

Now to achieve the above operation,please follow the below steps:

1)Create an "Image Upload" field (ex:ImageUploadField)

2)Add the token of above created field in your doc template (ex:{!ImageUploadField})

3)Add a key "CustomClassFilter" in shared.properties file as below and restart the server.

CustomClassFilter=(sun.net.ftp.*)|(java.net.*)|(java.lang.*)|(java.io.*)|(sun.net.www.protocol.*)|(java.awt.*)|(javax.imageio.*)|(sun.misc.*)

4)Create an object script trigger and copy the below code in trigger section:

var url=new Packages.java.net.URL("{!#HOSTED_FILE.qkAtE82oQyu17TI0PdtxaQ}");

var img=new Packages.javax.imageio.ImageIO.read(url.openStream());

var bos=new Packages.java.io.ByteArrayOutputStream();

var imageString="";

new Packages.javax.imageio.ImageIO.write(img,"jpg",bos);

var imageBytes=bos.toByteArray();

var encoder = new Packages.sun.misc.BASE64Encoder();

imageString=encoder.encode(imageBytes);

bos.close();

rbv_api.println(imageString);

rbv_api.setBinaryFieldValue("Account_1", "{!id}", "ImageUploadField", imageString, "image/jpg", "some file name");

rbv_api.runTemplate("Account_1", "{!id}", "QpVnYn1xTiWSrcdPFFRdTw");

Please let us know in case you need any assistance.

Regards,

Shiva

This thread is closed