You are here:
Dynamic Images in Server-Side Document Generation
Insert images such as product photos, barcodes, or pie charts in your generated DOCX and PDF documents by using image tokens in a Microsoft Word or Microsoft PowerPoint document template.
Required Editions
| Available in: Lightning Experience |
| Available in: Professional, Enterprise, Unlimited, and Developer Editions |
Place image tokens anywhere within a document template, such as in paragraphs, tables, and text boxes. Use a token in a header or footer or within a repeating content section to pass an array of images. Define the height and width of the images in Omnistudio Data Mapper Transform. By default, image tokens are supported within the Token Data and Token Data Content Document fields of the Document Generation Process. You can also use a custom Apex class to load a blob for dynamic image rendering using IDs, URsL, or other strings and identifiers. Store images in Files, on the Documents tab of a contract, or in the Notes and Attachments section of an object as a contract document, or in rich text fields.
If you don't have an OmniStudio license in your org, you can add dynamic images to
generated documents by using Context Service. Add image tokens to your document
template using the IMG_tokenname_src format. To control image dimensions,
use IMG_tokenname_height and IMG_tokenname_width tokens.
The src field accepts a Salesforce Content Document ID or file name. When
multiple files have the same name, the first match is used. See Token Naming Conventions for Context Service Document
Generation and Example: Generating a Contract Document by Using Context
Service.
To use default image dimensions without manually specifying height and width, transform context data with Data Processing Engine (DPE) and Context Service. SeeTransform Context Data for Document Generation. For an image-specific example, see Sample Context Definitions for Context Transformation in Document Generation
To set up your dynamic images using Data Mappers, follow these instructions:
- Upload Images in Salesforce for Server-Side Omnistudio Document Generation
Store images in the Rich Text field, Files, and Notes and Attachments of an object. You can save images in any location; however, for all images to render in the same generated document, make sure you store them in a single repository. - Configure Custom Image Fields for Server-Side Omnistudio Document Generation
Create a custom text field for any object that you want to fetch your image from. To render the image in the generated document, you must map the image API name from your object by using Omnistudio Data Mapper. - Map Image Name to Custom Image Field for Server-Side Omnistudio Document Generation
After you upload an image to the org and create a custom field on the object, map the image name to the custom field. Use Omnistudio Data Mapper to render the image in the generated document. - Map Image Tokens in the Omnistudio Data Mapper for Server-Side Omnistudio Document Generation
Use image tokens in a Microsoft Word or Microsoft PowerPoint document template to insert dynamic images in generated DOCX and PDF files. The image token must start with IMG_, such as {{IMG_header}}. Salesforce supports single-image, multiple-image, and loop-image tokens. Use Data Mappers to extract images from the org and define their height and width. - Retrieve Images During Server-Side Omnistudio Document Generation With Sample Custom Class
To retrieve images during server-side document generation, create an Apex class in your org that exposes the getImageContentBlob() method. During Server Side document generation, Salesforce calls this method to retrieve Base64-encoded image data. In your document generation request, pass image token data for each image token. Set the IMG_ token’s src value to a lookup key that matches a key in the imageContentMap returned by getImageContentBlob(). Salesforce uses this mapping to resolve and insert the image during document generation.

