Category

Using Images

Displaying checkboxes

By Documentation, S-Docs Cookbook, Using Images No Comments

If you want to create a document that contains checkbox images rather than “True” or “False” values, you can do so in two different ways.

Display Checkboxes With The Checkbox Merge Field Attribute

The easiest way is to add the checkbox merge field attribute to any boolean field that you want to display as a checked or unchecked checkbox.

Example Merge Field:

[code lang="html"]{{!Opportunity.Checkbox__c}}[/code]

Standard Checkboxes:

Display a standard checkbox (dotted white border with black check) that is checked if the boolean field is true, and unchecked if it is false:

[code lang="html"]{{!Opportunity.Checkbox__c checkbox="true"}}[/code]

Display a standard checkbox (dotted white border with black check) that is unchecked if the boolean field is true, and checked if it is false:

[code lang="html"]{{!Opportunity.Checkbox__c reverse_checkbox="true"}}[/code]

Black Checkboxes:

Display a black checkbox (solid black border that fills in black with a white checkbox) that is checked if the boolean field is true, and unchecked if it is false:

[code lang="html"]{{!Opportunity.Checkbox__c checkbox="black"}}[/code]

Display a black checkbox (solid black border that fills in black with a white checkbox) that is unchecked if the boolean field is true, and checked if it is false:

[code lang="html"]{{!Opportunity.Checkbox__c reverse_checkbox="black"}}[/code]

Radio Buttons

Display a radio button that is checked if the boolean field is true, and unchecked if it is false:

[code lang="html"]{{!Opportunity.Checkbox__c checkbox="radio"}}[/code]

Display a radio button that is unchecked if the boolean field is true, and checked if it is false:

[code lang="html"]{{!Opportunity.Checkbox__c reverse_checkbox="radio"}}[/code]

Learn more about merge field attributes here.

Display Checkboxes With CSS

Checkboxes can also be displayed using CSS styling similar to the following example:

[code lang="html"]<style type="text/css">.checkbox {
border: 1px solid black;
padding-left: 2px;
padding-bottom: 2px;
height: 9px;
width: 9px;
}
</style>
CHECKBOX
<div class="checkbox"> </div>[/code]

Display Checkboxes With Formula Fields

You can also display checkboxes by leveraging a formula field.

By adding the following formula field to your object, you can easily leverage it to place checkbox images into your S-Docs. (You do not need to add the field to the page layout.)

Note: Your formula field should have a Formula Return Type of Text and should be referenced as rich-text when merging into a template. The field used in the example, IsAccount__c, should be a checkbox field on your object that is checked by default.

[code lang="html"]IMAGE(
IF(IsAccount__c, '/img/checkbox_checked.gif', '/img/checkbox_unchecked.gif'),
'CheckBox'
)[/code]


Embedding Google Charts into your document

By Documentation, S-Docs Cookbook, Using Images No Comments

Introduction

Leveraging Google Charts API provides a great way to include dynamic charts in your S-Docs.
You can find more information on Google charts here: http://code.google.com/apis/chart/

Create A Remote Site Setting:

This functionality requires an entry in Salesforce's Remote Site Settings.

  1. Click Your Name > Setup > Security Controls > Remote Site Settings.
  2. Click New Remote Site button.
  3. Set the Remote Site Name field to SDOCS3.
  4. Set the Remote Site URL field to http://chart.apis.google.com
  5. Make sure Active is checked and then click the Save button.

Google Chart Examples

Here are a few examples of Google charts:

Google-charts

The charts work by passing the Salesforce data to the Google API, which in turn dynamically builds and returns the chart as a PNG image.

Security Note: Unlike S-Docs, which works entirely within the Salesforce.com platform, Google charts are hosted remotely. Depending on the chart, your data is passed from Salesforce to Google. Your security team would need to determine if this is an acceptable practice.

Images are rendered by using one URL request per chart. For example, you can manipulate the values in the following URL to render a different pie chart:
[code lang="html"]http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Jan|Feb[/code]
The link above will return the following image:

example-chart

As you may begin to see, using Google Charts API is all about creating these URLs where you pass in the data points, legends and chart options. Depending on the chart, some of these URLs can be long and a bit complex.

Option 1: Use Formula Fields For Your Google Charts

Rather than building complex logic within S-Docs to create these URLs, we again leverage Salesforce formula fields to do the heavy lifting.

Here is a great tutorial from Salesforce on how to create Google Charts using a formula field:

http://wiki.developerforce.com/index.php/Using_Formulas_and_Google_Charts_to_Visualize_Data

The above tutorial will walk through how to build the following formula field to display a Won/Loss pie chart:

[code lang="html"]IMAGE("http://chart.apis.google.com/chart?cht=p3&chd=t:" & Text(Won__c/(Won__c + Lost__c)) & "," &
Text(Lost__c/(Won__c + Lost__c)) & "&chs=275x100&chf=bg,s,F3F3EC&chl=Won|Lost&chco=5555ff", "chart text")[/code]
Then, we simply drop this formula field into our S-Doc template (be sure to check Contains Rich Text box).

Option 2: Use The Google Chart API URL In Your S-Docs Template

While more complex, another approach is to build the Google Chart API URL in your S-Doc Template and then mix in field values. This may offer you greater control. Using syntax similar to the following, you could add the image, where ChartLegend__c would just contain the value “Jan|Feb.”
[code lang="html"]lt#img src= quot#http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=
{{!MyObject__c.ChartLegend__c}}quot# /gt#[/code]

Improving performance on pages with many Google charts:

The Google documentation offers a good performance tip if you plan to embed 5 or more charts. By appending a 1-9 before the “chart.apis.google.com,” you can have the browser load the charts simultaneously. For example:

  • http://0.chart.apis.google.com/chart?cht=...
  • http://1.chart.apis.google.com/chart?cht=...
  • http://2.chart.apis.google.com/chart?cht=...
Note: S-Docs does not support the Google Visualization API.


Adding Dynamic Images into Templates

By Documentation, S-Docs Cookbook, Using Images No Comments

Introduction

While you can insert static images into your templates, S-Docs can also insert dynamic images. For example, say you want to create a letter that includes an image of the representative’s signature at the bottom of a page. Or similarly, you may want to include an image of your product on a Product Specifications PDF. Rather than cloning the same template many times (once for each unique image), you would rather have just one template that dynamically includes the right image. You can accomplish this in several ways.

Option 1: Use a rich text field

This is perhaps the easiest method. You first upload your image into a standard Salesforce rich text field on your record detail page. Then, open the template in which you want to add the image, click on the Template Editor button, click on the Insert Field button, select the rich text field, click on the Contains Rich Text checkbox, and finally click on the Insert button. Your documents will now render the rich text content for that record wherever you placed this field.

Note: This option is only available for PDF documents. If your rich text contains many items or elements, it may not render precisely. This is because Salesforce uses a rich-text editor that auto-formats rich text content and this formatting cannot be overridden through a source editor. It is a better practice to use the S-Docs editor to control document layout rather than inserting a complex rich-text field into a template. By doing so, you also maintain template formatting in a central location (the S-Docs template) versus fragmented design elements located in rich text fields throughout individual records.

Option 2: Use a standard text field that contains the entire image markup

You can also use a standard Salesforce text field whose value contains the complete image element tag that you want to include. Each record would potentially contain a different link that corresponds to the applicable image.

For example, set the value of a ProductImage__c field on a Product record to:
[code lang="html"]PRODUCT IMAGE:<br><img scr=”/host/Product123Image.png” />[/code]
Then, using the S-Docs template editor, click on the Insert Field button, select the field, and then be sure to click on the Contains Rich Text checkbox.

This is a simple approach but has limited usage. It is useful for images such as representative signatures, where they are centrally controlled by an administrator, they do not change frequently, and the user would not normally need to view them in the Salesforce user interface along with the record. Since this is a text field, if you were to include this field on a page layout, it would not render as an image – users would only see the text shown above when viewing the record detail in the Salesforce UI. Therefore, it would not be appropriate for end-users who upload their own images frequently (e.g. a scanned photograph of a damage claim) or wanted to view the actual image in Salesforce within the record detail page.

Option 3: Use a formula field to display an image

Building on option 2, you can leverage a Salesforce formula field to create the image path and also display the image within the Salesforce record detail. You would then drop the formula field into your S-Docs template with the Contains Rich Text option checked (as described in the previous option). The formula field would contain something similar to the following:
[code lang="html"]IMAGE("/CompanyIntranet/Products”+ myObject__c.ProductID__c + “.png")[/code]
This option requires some planning so that the image field name can be programmatically derived.

Option 4: Build an image URL within the S-Docs template

This is a combination of options 2 and 3, but would not require a formula field. You can use a record’s existing field value to help build the correct image path, but you create the full path value within the S-Docs template, not in the Salesforce field.

For example, to include a dynamic product image or agent's signature, you can use something similar to the following in your document template source:
[code lang="html"]lt#img src=quot#http://intranet/{{!Product2.ProductPath__c}}.png quot# /gt#
lt#img src=quot#{{!Opportunity.Owner.SignatureURL__c}}quot# /gt#[/code]
The field value should be a URL that points to either an image in your Salesforce documents folder or an external image hosted on the public internet. In the second example, the field should contain the entire path including the ‘http://’ prefix.

Since the image path is text (not markup) it should only be surrounded by double curly braces, as shown above. The special notation for  <, >, and quotes, using lt#, gt#, quot# respectively, is used to instruct S-Docs that this markup needs to be evaluated rather than rendered literally. Having this flexibility gives you total control of how you want a field interpreted within the S-Docs template.

In order to compensate for relative URLs (e.g src=“/servlets/…”) that Salesforce automatically generates, S-Docs will automatically replace the relative path with the complete path, including the correct Salesforce.com instance (e.g. src=”https://na1.salesforce.com/servlets/...”). Doing this ensures your embedded images render correctly when viewed by others. If you wish to override this behavior and use a relative URL, you should specify the path to include the “http” (e.g. src=”http://servlet/”).

Discussion

Once you have inserted a marked-up field into your template, you will notice three sets of braces that surround your field, for example:
[code lang="html"]{{{!Product2.ProductImage__c}}}[/code]
The extra pair of curly braces instructs S-Docs to interpret this field rather than just displaying the stored value. Without this, S-Docs would not know whether a field containing the value “<img src=“//host/Product123Image.png” />”  should be displayed as the text quoted or substituted with the actual image when rendered. Whenever you add a field using the template editor and click on the Contains Rich Text checkbox, S-Docs will evaluate the value regardless of the actual Salesforce field type (Rich Text or otherwise).

If images outside of Salesforce are used in the S-Docs template directly, or dynamically through a merged image field, you must whitelist the URL domain (using Setup > Remote Site Settings) to avoid broken image icons in the PDF.


Embedding static images into your document

By Documentation, S-Docs Cookbook, Using Images No Comments

Embed Static Images Using Code

To embed static images, like a company logo, in your documents, you can use an image tag similar to the following in your S-Docs template source.

[code lang="html"]<image src="http://publicsite/imagename.png" />[/code]

This may be the simplest approach if you are emailing HTML content or wish to embed an image pixel for email tracking. However, keep in mind that if this image is not stored in your Salesforce org or if the host server is not under your control, the linked image may change and therefore is not guaranteed to work.

Embed Background Images/Watermark

A background image or watermark can be added to your document by including the following CSS styling with your image URL.

[code lang="html"]<style type="text/css">body{ background-image: url("https://background.image.url"); background-attachment:fixed; background-position: center; background-repeat:no-repeat;background-size:400px; } </style>[/code]

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

Embed Static Images That Are Stored As Salesforce Documents

You can also embed images that are stored as Salesforce documents.

[1] Use the Add Image button on the template editor toolbar to open a menu for adding images into S-Docs.
[2] Click Browse Server to search and add the desired image from your Salesforce documents folder.

If you intend to send a document externally that requires access to the image at view-time (e.g. an email template), be sure that the Salesforce document record, which contains the image, is set for public visibility and copy the image's full URL: 1. Check the Externally Available Image box to make the image visible on the public internet. 2. Right click the image itself and copy its full URL. In Google Chrome, you would right click the image and click Copy image address. In Firefox, you would right click the image and click Copy image location. In Internet Explorer, you would right click the image and click Properties, and then copy the URL from the "Address (URL)" field in the following pop-up window.

Embedding Static Images (2)

You can now add this image into your template by clicking the Add Image button icon in the template editor and pasting the URL you copied into the URL field of the "Image Properties" window.

Embed Static Resources As Images

You can also embed static resources as images within your S-Docs templates using the following code:

[code lang="html"]<img src="/resource/STATIC_RESOURCE_API_NAME/PATH_TO_IMAGE" />[/code]

For example, your static resource reference might look like this:

[code lang="html"]<img src="/resource/Pckg__Pckg_Images/FolderInTheResourceZipFile/the_image.png" />[/code]

Embed Static Images In DOC Templates

For DOC templates, in order to ensure that your images are scaled correctly in the final generated document, it is important to check Embed Images in the Page Settings tab of the template editor.

Additionally, the image source should be in this format (using the style attribute):

[code lang="html"]<img src="..." style="height: ...px; width: ...px;" />[/code]

Rather than this format:

[code lang="html"]<img src="..." height="..." width="..." />.[/code]

Note the difference in the height and width. If you use the second example, the images will show up as tiny squares in the generated document.
Finally, the user must click Enable Editing in Microsoft Word for images to download in the generated document.

Note: For images that you need to have externally available, note that the Browse Server button will use the local path rather than the full path, and your image will not be available externally (even if Externally Available Image is checked).
If you want this image to be visible externally (such as including it in an email sent to your customers), you must append the base URL to the beginning of the local path in the source code; e.g. if the Browse Server button uses this path: /servlet/servlet.ImageServer?id=01536000001T3ZE&id=00D36000000v29C&lastMod=147065920900), you must add https://na30.salesforce.com to the beginning to make the image externally available.

You can also forgo using the Browse Server button and use the full path from Classic view rather than the local path (e.g. use: https://na30.salesforce.com/servlet/servlet.ImageServer?id=01536000001T3ZE&oid=00D36000000v29C&lastMod=147065920900 rather than: /servlet/servlet.ImageServer?id=01536000001T3ZE&id=00D36000000v29C&lastMod=147065920900) when referencing the image in your S-Docs template. This is why we copied the image's full URL and pasted it into the "URL" field of the "Image Properties" window in the steps above.

Top