# Insert Images

## What Are Images in S-Docs?

Images in S-Docs allow you to include visual elements in your generated documents, from company logos and product photos to signatures and watermarks. S-Docs supports both static images (that remain the same across all documents) and dynamic images (that change based on record data).

## How Are Images Used in S-Docs?

Images enhance document professionalism and provide visual context that text alone cannot convey. Common use cases include:

* **Company logos and branding**: Headers, footers, and letterheads
* **Product images**: Catalogs, specifications, and proposals
* **Signatures**: Contracts and approvals
* **Charts and diagrams**: Reports and presentations
* **Watermarks**: Draft stamps, confidential labels, and background branding

***

## Static Images vs. Dynamic Images

Understanding the difference between static and dynamic images helps you choose the right approach for your needs.

### Static Images

Static images are the same across all generated documents. Examples include company logos, standard headers, or consistent branding elements.

**Use static images when:**

* The image never changes regardless of the record
* You need consistent branding across all documents
* The image is part of your document template design

### Dynamic Images

Dynamic images change based on the record being used to generate the document. Examples include product photos, employee headshots, or custom signatures.

**Use dynamic images when:**

* Different records need different images
* Images are uploaded or selected by users
* You want one template to handle multiple scenarios

***

## Adding Static Images

There are several methods for embedding static images into your S-Docs templates.

### Method 1: Using an Image URL

The simplest approach is to reference an image URL directly in your template source:

{% code title="Example" %}

```html
<img src="https://publicsite.com/imagename.png" />
```

{% endcode %}

This method works well for:

* Images hosted on public websites
* Email templates (where the recipient needs to access the image at view-time)
* Quick testing and prototyping

**Important:** If images are stored outside of Salesforce, you must create a Remote Site Setting for the image's URL domain (see "Troubleshooting" section below).

### Method 2: Using the Template Editor Add Image Button

The template editor provides a visual interface for adding images with two tabs: **Image Info** and **Upload**.

{% stepper %}
{% step %}

#### Open the Template Editor

1. Open your template in the Template Editor
2. Click the **Add Image** button on the toolbar

<figure><img src="/files/UNP3zXPlVMKxXj8qq1au" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Choose one of the following options

Select either the Image Info tab or the Upload tab (detailed below).
{% endstep %}
{% endstepper %}

#### Image Info Tab

The Image Info tab offers two ways to add images:

**Option A: Browse Server**

{% stepper %}
{% step %}
Click **Browse Server** to search for existing images in your Salesforce documents folder
{% endstep %}

{% step %}
Select your desired image
{% endstep %}

{% step %}
Click to insert the image
{% endstep %}
{% endstepper %}

**Note:** If you're sending documents externally (like email templates) and you selected an image using Browse Server, you need to ensure the Salesforce document record is set to externally available:

{% stepper %}
{% step %}
Navigate to the Documents object in Salesforce Classic
{% endstep %}

{% step %}
Find your image's Document record
{% endstep %}

{% step %}
Check the **Externally Available Image** checkbox
{% endstep %}

{% step %}
Save the record
{% endstep %}
{% endstepper %}

**Option B: Paste Image URL**

{% stepper %}
{% step %}
Copy the full URL of your image (right-click the image → "Copy image address")
{% endstep %}

{% step %}
Paste the URL into the **URL** field in the Image Info tab
{% endstep %}

{% step %}
Click to insert the image
{% endstep %}
{% endstepper %}

This works the same way as adding an image URL directly in the template source code.

#### Upload Tab

The Upload tab allows you to upload new images directly from your computer:

{% stepper %}
{% step %}
Click the **Upload** tab
{% endstep %}

{% step %}
Click **Browse** to select a file from your computer
{% endstep %}

{% step %}
Select your image file
{% endstep %}

{% step %}
Click to upload and insert the image
{% endstep %}
{% endstepper %}

**Important advantage:** Images uploaded through the Upload tab are **automatically set as externally available**, so you don't need to manually configure the Externally Available Image checkbox.

**Note:** S-Docs also supports embedding images as Content Distribution URLs, which render consistently and securely across all generated documents, aligning with Salesforce best practices.

### Method 3: Using Static Resources

You can embed static resources as images using the following code:

{% code title="Example" %}

```html
<img src="/resource/STATIC_RESOURCE_API_NAME/PATH_TO_IMAGE" />
```

{% endcode %}

**Example:**

{% code title="Example" %}

```html
<img src="/resource/Pckg__Images/FolderInZipFile/image.png" />
```

{% endcode %}

This method is ideal for:

* Package development
* Images that are part of your deployment
* Version-controlled branding assets

### Method 4: Adding Background Images or Watermarks

To add a background image or watermark that appears on every page:

{% code title="Example" %}

```html
<style type="text/css">
body {
    background-image: url("https://background.image.url");
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
}
</style>
```

{% endcode %}

**Note:** The background image/watermark will be the same for every page of the document. For different images on different pages, use the DOCX document format.

***

## Adding Dynamic Images

Dynamic images allow a single template to display different images based on record data.

### Method 1: Use a Rich Text Field

This is the easiest method for dynamic images:

{% stepper %}
{% step %}
Upload your image into a standard Salesforce rich text field on your record detail page
{% endstep %}

{% step %}
Open your template in the Template Editor
{% endstep %}

{% step %}
Click **Insert Field**
{% endstep %}

{% step %}
Select the rich text field
{% endstep %}

{% step %}
Check the **Contains Rich Text** checkbox
{% endstep %}

{% step %}
Click **Insert**
{% endstep %}
{% endstepper %}

The document will now render the rich text content (including images) wherever you placed this field.

**Note:** This option is only available for PDF and DOCX documents. Rich text fields with many items or complex formatting may not render precisely. It's better practice to use the S-Docs editor to control document layout rather than inserting complex rich-text fields.

### Method 2: Use a Text Field Containing Image Markup

You can use a standard Salesforce text field whose value contains the complete image element tag:

**Example field value:**

{% code title="Example" %}

```html
PRODUCT IMAGE:<br><img src="/host/Product123Image.png" />
```

{% endcode %}

Then insert the field using the Template Editor:

{% stepper %}
{% step %}
Click **Insert Field**
{% endstep %}

{% step %}
Select the field
{% endstep %}

{% step %}
Check the **Contains Rich Text** checkbox
{% endstep %}

{% step %}
Click **Insert**
{% endstep %}
{% endstepper %}

**Use this method for:**

* Images controlled by administrators
* Images that don't change frequently
* Representative signatures or stamps

**Limitations:** Since this is a text field, users will see the markup text (not the image) when viewing the record in Salesforce, making it less user-friendly for frequently updated images.

### Method 3: Use a Formula Field to Display an Image

Building on Method 2, you can use a Salesforce formula field to create the image path programmatically:

{% code title="Example" %}

```
IMAGE("/CompanyIntranet/Products/" + myObject__c.ProductID__c + ".png")
```

{% endcode %}

Then insert the formula field into your template with **Contains Rich Text** checked.

**Benefits:**

* Image displays properly in Salesforce record detail pages
* Programmatically builds the correct path
* More user-friendly than text fields

**Requirements:** Image file names must follow a consistent, predictable pattern.

### Method 4: Build an Image URL Within the S-Docs Template

This method creates the full image path within the S-Docs template itself, without requiring a formula field.

**For S-Docs versions below 7.0:**

{% code title="Example" %}

```
lt#img src=quot#https://intranet/{{!Product2.ProductPath__c}}.pngquot# /gt#
lt#img src=quot#{{!Opportunity.Owner.SignatureURL__c}}quot# /gt#
```

{% endcode %}

The special notation (`lt#`, `gt#`, `quot#`) instructs S-Docs to evaluate the markup rather than render it literally.

**For S-Docs version 7.0 and later:**

{% code title="Example" %}

```html
<img src="https://intranet/{{!Product2.ProductPath__c}}.png" />
<img src="{{!Opportunity.Owner.SignatureURL__c}}" />
```

{% endcode %}

**Important:** The field value should be a URL pointing to either:

* An image in your Salesforce documents folder
* An external image hosted on the public internet

The field should contain the entire path including the `https://` prefix.

**Best Practice:** Build a full image URL in a custom field so the base URL can be changed in one place if needed, rather than updating every template. This is especially important when migrating templates between orgs.

***

## Understanding Triple Curly Braces

When you insert a field marked as "Contains Rich Text," you'll see three sets of braces:

{% code title="Example" %}

```
{{{!Product2.ProductImage__c}}}
```

{% endcode %}

The extra pair of curly braces instructs S-Docs to **interpret** the field value as markup rather than display it as text.

**Without triple braces:**

```
```

Displays: `<img src="//host/Product123Image.png" />`

**With triple braces:**

```
```

Displays: The actual image

***

## Working With Images in DOC Templates

For DOC templates, additional configuration is required to ensure images scale correctly.

### Template Settings

{% stepper %}
{% step %}
Navigate to the **Page Settings** tab in the Template Editor
{% endstep %}

{% step %}
Check **Embed Images**
{% endstep %}
{% endstepper %}

### Image Format Requirements

Use the **style attribute** format:

{% code title="Correct" %}

```html
<img src="..." style="height: 100px; width: 200px;" />
```

{% endcode %}

**Do NOT use:**

{% code title="Incorrect" %}

```html
<img src="..." height="100" width="200" />
```

{% endcode %}

Without the style attribute, images will appear as tiny squares in generated documents.

### User Action Required

Users must click **Enable Editing** in Microsoft Word for images to download in the generated document.

***

## Best Practices

* **Use the Upload tab for new images**: When adding new images from your computer, use the Upload tab to automatically handle external availability
* **Point sandbox templates to production images**: When working in sandbox, reference image URLs from your production org to avoid updating images when migrating templates
* **Use full URLs, not relative paths**: Build complete URLs (e.g., `https://na30.salesforce.com/servlet/...`) instead of relative paths (e.g., `/servlet/...`) for better portability between orgs
* **Organize images logically**: Use descriptive file names and folder structures for easy maintenance
* **Test across formats**: Verify images render correctly in PDF, DOCX, and HTML formats
* **Consider file size**: Large images can slow document generation; optimize images before uploading
* **Use static resources for packages**: If developing managed packages, use static resources for version control and deployment

***

## Troubleshooting

If images show up in the template editor but do not load in generated documents, there are three common causes and resolutions.

### Issue 1: Image URL Redirects to Another Page

If your image URL redirects to another page, Salesforce may prevent it from loading.

**Resolution:**

{% stepper %}
{% step %}
Navigate to Setup → type "Custom Settings" in Quick Find → click **Custom Settings**
{% endstep %}

{% step %}
Locate the **SDocsSettings** record and click **Manage**
{% endstep %}

{% step %}
If no record exists, click **New**. Otherwise, click **Edit**
{% endstep %}

{% step %}
Check the **Stabilized URLs Checked** field
{% endstep %}

{% step %}
Click **Save**
{% endstep %}
{% endstepper %}

Images should now load correctly.

### Issue 2: Image URL is From External Source

If your image URL is from outside Salesforce, you must allowlist the domain through Remote Site Settings.

**Resolution:**

{% stepper %}
{% step %}
Navigate to Setup → type "Remote Site Settings" in Quick Find → click **Remote Site Settings**
{% endstep %}

{% step %}
Click **New Remote Site**
{% endstep %}

{% step %}
Enter the following:

* **Remote Site Name**: externalImageSDocs (or any descriptive name)
* **Remote Site URL**: The image URL domain only

**Example:** If your full image URL is `https://www.google.com/images/logo.png`, enter `https://www.google.com` as the Remote Site URL.
{% endstep %}

{% step %}
Click **Save**
{% endstep %}
{% endstepper %}

Your external image should now load correctly.

### Issue 3: Image From Salesforce Documents is Not Externally Available

If your image was added from Salesforce documents using Browse Server (not uploaded through the Upload tab), it must be manually set to Externally Available.

**Resolution:**

{% stepper %}
{% step %}
Navigate to the **Documents** object in Salesforce Classic (Click the **+** (All Tabs) symbol to find Documents)
{% endstep %}

{% step %}
Find the Document record for your image and click its name
{% endstep %}

{% step %}
Check the **Externally Available Image** checkbox
{% endstep %}

{% step %}
Click **Save**
{% endstep %}
{% endstepper %}

The image should now load correctly.

**Note:** Images uploaded through the **Upload tab** in the Add Image window are automatically set as externally available and do not require this manual step.

### Issue 4: Images Not Appearing After Org Migration

**Symptoms:** Images worked in your original org but don't appear after migrating templates to a new org.

**Causes:**

* Image URLs contain the old org's instance (e.g., `na30.salesforce.com` instead of the new instance)
* Relative URLs aren't resolving correctly in the new org

**Resolution:**

* Use full URLs with the correct instance
* Consider using formula fields to build URLs dynamically
* Update static image references to point to the new org's resources

### Issue 5: Broken Image Icons Appear

**Symptoms:** Broken image icons appear instead of images in generated PDFs.

**Common causes:**

* Missing Remote Site Settings for external URLs
* Image not set as Externally Available
* Incorrect or expired image URL

**Resolution:** Follow the troubleshooting steps for Issues 2 and 3 above.

***

Working with images in S-Docs allows you to create professional, visually engaging documents that enhance your brand and improve communication with customers and stakeholders. Whether using static images for consistent branding or dynamic images for personalized content, S-Docs provides flexible options to meet your needs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/sdocs/template-architecture/images-in-s-docs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
