Embed Images/Signatures in Word/Excel/PowerPoint

*Note: This article is for embedding images that are sent over in the Merge Data.  Not embedding signatures from e-signature services like DocuSign, AdobeSign, HelloSign, etc.

*Also Note: All images merged over must be publically accessible so we can download it to our system.

Due to the way Microsoft Office files are designed, embedding dynamic images in an Office document is not as simple as when you are using our Builder.  But, it is still possible with a little bit of work.  Below is a quick tutorial on how you can embed a dynamic image (signature, uploaded picture, etc) into your Word DOCX documents.  For this example, we will be embedding a Formstack signature in our DOCX.

First thing you will need to do is embed an image in your document as placeholder for where you want the final image to go.  The size that you make this image placeholder will be the size that the final image will be.  It is important to note that you must use a placeholder with the same file format (JPEG or PNG) as the final image.

If you do not have an image placeholder to use, we have built an image generator that you can use.  Here is an example URL:

http://www.webmerge.me/images/image.php?width=300&height=100&type=png

If you go to that URL, it will load an image.  Simply right-click the image and copy the image, then paste that image into your word document.  In the URL, you will notice there is width and height setting so you can control the size of the image. 

Also, the type parameter (possible values: png or jpeg) controls the type of the image.  Go ahead and change those parameters to create a customized image.


The next step is the setup the variable placeholder for your image.  You can put this placeholder anywhere in your document – it is simply used to map the image URL to the image element in your document.  For the most part, it’s the same format as other variables, but we will add a little more info. Below is an example variable placeholder for the image:

{$MyImage|image:1:png}

In the above example, the variable name is “MyImage”, then the “|” indicates options after.  Each image in a DOCX is stored using a numerical identifier, so the “1” in the image indicates that identifier. 

Once you have that in place, you’re all set!

 

**If you are inserting more than 1 image in your document, you'll want to make sure you use different images as the placeholders because Word will treat them as the same image.  If you are using our image generator, simply add a pixel to the width or height of the image and that will do the trick!

 

Inserting a dynamic image (Word and PPT only)

If you are looping through a list of images, using the placeholder method above will produce the same image over and over again.  To fix this, we've created a new way to add an image to your document using the following tag:

{$image|insert_image:width:height:max_width(optional):max_height(optional)}

Here's a real example:

{$image|insert_image:300:100}

To break down this tag, $image is the merge field, 300 is the width, and 100 is the height (you can change these to create the correct size image).

You would place this tag in the spot that you want your image inserted and it will be replaced with your image when the document is merged.

If you wanted to automatically size the height to keep proportions, you can use a "0" for the height like this:

{$image|insert_image:300:0}

If you'd like to set a maximum height to your image, you would use a tag like this:

{$image|insert_image:300:0:0:200}

Was this article helpful?
10 out of 20 found this helpful

Comments

49 comments
  • Hi Jeremy,

    thank you, I am glad I asked. It works fine for me. The only small restriction is that the pics all need to be of the same size, but a little Photoshop should help on that side. Thanks for the great support.

    0
  • Hey Jeremy,
    Can we use a base64 encoded image to merge an image to a document or does it need to be a URL?
    Thanks,
    Steve

    0
  • Hi Jeffrey,

    The "tableif" is only used inside a table, so you'll want to use "if" instead like this (the {continue} code skips to the next item in the loop):

    {foreach from=$_0.record.recs_information item=_photo2}{if empty($_photo2.record.rec_expl)}{continue}{/if}
    Explanation: {$_photo2.record.rec_expl}
    {$_photo2.record.recs_photo|insert_image:600:0:0:325}{/foreach}

    0
  • I need to place the first half of the URL in front of my merge tag as the tag only contains the file name not its location. how do i do this?
    0
  • Hi Jeremy where can I find documentation on everything there is to do with insert_image? Our placeholder is at the end of this and we are wanting to maximize the display in the page if possible - or are we stuck with guessing a width and hoping the height does not take up more than one page...are there any other parameters that could help, etc? It appears that we are forcing 450px wide and accepting whatever height that proportions out to?

    {foreach from=$_photos item=_photo}
    {$_photo|insert_image:450:0}
    {/foreach}

    0
  • Thank Jeremy,

    Is there a way for the foreach loop to search two arrays simultaneously? I need to pull two different Ids at the same time to build the URL string without nesting the foreach loops.

    Thanks,

    0
  • Hi Sundell,

    Yes, if the image is larger than the max, then it will shrink the image (and keep proportions). The DPI should be around 96 pixels per inch

    0
  • Hi Steve,

    We have a 100MB limit for data being sent to our system, so anything below that!

    Thanks,

    0
  • Hi Jonathan,

    Unfortunately, there isn't a way to remove the placeholder in an Excel document due to formatting restrictions of an Excel document. Sorry! I would suggest setting up a 2nd template without the image, then use Data Routing to pick which template to use based on if there's an image value or not

    0
  • Hi Jeremy, this works great if you have static image content. But what if you a proposal with a product table where each product has its own product picture?

    I am using your tablerow tag and then this for the image: {$_lineitem.URL_productpicture__c|image:2:jpg}. The URLs for the image pics are being passed over in an array from Salesforce, but since it always says "image:2:jpg" all products have the same picture in the merged document (that of the first product).

    Would there be any way of writing code that would have the number for the picture (in this case the 2) increment with each loop in the tablerow? That would be really cool.

    Thank you,
    Gregor

    0
  • Hello,

    When I wrote {$MyImage|image:1:png} it shows me the error:
    There is an error in your document: Syntax Error in template "string:" "
    {$MyImage|image:1:png}" unknown modifier "image"

    Can you please help me out?

    0
  • Also - is there a set DPI setting so that we can know how many PX spans the width beween L and R margins, etc? It looks like our document uses 0.5 LR margins - so we have 7.5 inches to work with - if I want to max the width out how many PX is that? I see 563 when 75 DPI, 1125PX at 150 DPI etc....just not sure what rules apply. Thanks again!

    0
  • Unfortunately, the "insert_image" functionality only works for Word and PowerPoint templates. I have updated the article to make this clear. Sorry! You'll need to use the image placeholder method (the top of the article).

    Thanks!

    0
  • Hi Gregor,

    Thanks for the question. We actually recently launched a new feature to fix this problem and our doc had not been updated yet. We have updated the article above to reflect the new functionality (look under the Insert dynamic image section at the bottom).

    Thanks!

    0
  • Hi Jeremy,
    Is there a way to use the tableif function with the foreach? I have a section of a document that may or may have photos sent. Below is an example of the current code without the tableif.

    {foreach from=$_0.record.recs_information item=_photo2}
    Explanation: {$_photo2.record.rec_expl}
    {$_photo2.record.recs_photo|insert_image:600:0:0:325}{/foreach}

    0
  • Hi Yuriy,

    You'll need to send the array of images in the merge data. Please submit a ticket and we'll help you one on one :)

    Thanks!

    0
  • Thank Jeremy that worked great

    0
  • it still does not seem to work the url is correct. I have coped the exact code you have pleaced in the above comment and replaced the exaple url with that of my own. the merge tag i am using is $signature and the data is coming across as the correct file name as when i use it without an image it displays the filename.but when i place it in as an image it does not display it has a white box with the red X
    0
  • Hi Chris,

    In Excel you have to use the "placeholder" method (the first example at the top of this help article) to embed the image. The "insert_image" does not work in Excel. Can you please confirm that you're using 2 unique image placeholders?

    Also, can you turn on Debug Mode to make sure we are receiving valid URLs to the images?

    0
  • Hi Chris,

    Please reach out to our support team and request a call from Sales and they'll get you connected for a quick call!

    0
  • Hey Jeremy,

    I fixed the URL issue, ZOHO Forms direct integration works there, zapier does not bring the url for the signature. I thought I had the placeholder correct. is it possible to set up a call?

    0
  • Hi Bill,

    Please submit a ticket to our support team and we can help you with your specific question. The short answer is yes you can grab data from multiple arrays, but it all depends on the format of your arrays.

    Thanks!

    0
  • Jeremy,
    Thanks for the quick response! Is there a file size limit when transferring a base64 encoded image?
    - Steve

    0
  • Hi Jeremy,

    I have a word document file with placeholders for images. This is to create yearbook pages that are being submitted through formstack. Last year with the generated files I was able to restore images to their original aspect ratios. I would click on the image, and under picture tools in word, in the crop menu, hit "fit" and the image would jump back to the aspect ratio as submitted. I can't seem to get these docs to do that.

    What do I need to do to my file to make this edit possible?

    0
  • It seems that image URL should be publicly accessible. Is that correct?

    0
  • Hi, Jeremy!

    Is it possible to replace an image in a Word Doc with a file upload from a Data Capture form instead of from a full URL path to an image?

    Best,
    Anne

    0
  • Hi Jeremy,

    Is it possible to do something like insert_image:0:0:300:200 where 300 and 200 are maximum dimensions but the proportion is always maintained?

    0
  • Hi Anne,

    Yes, follow the instructions in the above article :) If you need additional help, please create a support ticket and we'll help you from there!

    Thanks!

    0
  • can't get this working in excel. I get this written out from my dynamic tag as documented above (as a sample). But no image is rendered. what am i missing?

    [IMAGE url="https://storage.googleapis.com/gweb-uniblog-publish-prod/static/blog/images/google-200x200.7714256da16f.png" width="300" height="100" max_width="0" max_height="0"] 

    0

Please sign in to leave a comment.