When an image is stored in a Salesforce Rich Text field, Apsona renders it directly from the HTML markup using a normal merge field. However, Word cannot recognize the merge field as an image before the merge is executed, so the image cannot be resized within the template. The IMAGE tag also cannot be used directly because the field contains HTML markup rather than a standalone image URL.
To enable image resizing, create a JavaScript Calculated Field in the Apsona report to extract the image's source URL (src) from the HTML markup. Use the calculated field with the IMAGE tag in the Word merge template, specifying the required dimensions.
The following JavaScript function extracts the image URL:
function(html) {
if (!html) {
return "";
}
var match = html.match(/<img[^>]+src=["']([^"']+)["']/i);
return match ? match[1].replace(/&/g, "&") : "";
}({!Contact.Contact.Contact Picture})
Once the image URL is extracted, it can be used with the IMAGE tag, allowing the image dimensions to be controlled in the merged document.