Embed Images/Signatures in Word/Excel/PowerPoint

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.  To determine what number your image is, add &images=1 to the end of the URL when you are on the Manage File tab - this page will show you all of the images in your document.  The “png” in the placeholder represents the image type (possible values: png or jpeg).

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

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}

Have more questions? Submit a request

21 Comments

  • Avatar
    Lewis Hackfath
    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?
  • Avatar
    Jeremy Clarke
    Hi Lewis, You can do something like this: {$signature = "https://www.example.com/images/"|cat:$signature}{$signature|image:1:png}
  • Avatar
    Lewis Hackfath
    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
  • Avatar
    Jeremy Clarke
    Hi Lewis, I'll create a support ticket and help you from there
  • Avatar
    Alex Melzer

    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

    Edited by Alex Melzer
  • Avatar
    Jeremy Clarke

    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!

  • Avatar
    Alex Melzer

    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.

  • Avatar
    Yuriy Gavrilov

    Very nice!
    Have any ideas how to make array of image?))
    As input we have one email with different count of images so need to reproduce it in pdf with same count on image (better with auto fit on page), add some dynamic text and resend it. thanks for any suggestion.

    Edited by Yuriy Gavrilov
  • Avatar
    Jeremy Clarke

    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!

  • Avatar
    Anne Saulnier

    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

  • Avatar
    Jeremy Clarke

    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!

  • Avatar
    Anne Saulnier

    And now it works... I had the wrong image path in the variable, but appending the &images=1 on the manage file page showed me the way... You're awesome and fast. :-)

    Edited by Anne Saulnier
  • Avatar
    Ashley Whittemore

    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?

  • Avatar
    Jeremy Clarke

    Hi Ashley,

    The easiest thing to do is use our new "insert_image" functionality that has replaced the image placeholders. Then you can set a width (or height) and it will auto-size. Please look at the last section on the article above and give that a try (you won't need your image placeholders anymore)

  • Avatar
    Iliyaskhan Pathan

    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?

  • Avatar
    Jeremy Clarke

    Hi Iliyaskhan,

    Can you create a support ticket and send us your template so we can take a look?

  • Avatar
    Sundell Larsen

    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}

  • Avatar
    Jeremy Clarke

    Hi Sundell,

    We've just updated the help article to show the parameters, but there are 2 additional parameters you can use to set the max_width and max_height of the image:

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

    So an example might be:

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

    This would set the maximum height to 500

  • Avatar
    Sundell Larsen

    Thanks Jeremy, Does it clip or stretch/shrink when limits are reached?

  • Avatar
    Sundell Larsen

    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!

  • Avatar
    Jeremy Clarke

    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

Please sign in to leave a comment.
Powered by Zendesk