Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Tabled of Contents

Table of Contents

WordWriter allows you to insert jpg, gif, bmp, and png images in merge fields. You can insert images repeat block and main document merge fields. There are two ways to insert an image into a merge field:

Using a Placeholder

To insert an image in a merge field using a placeholder:

  1. Create or open a WordWriter template (for instructions, see Creating a WordWriter Template).
  2. Place the cursor within a merge field.
  3. Open the Insert menu and select Picture -> From File...
  4. Select a jpg, gif, bmp, or png image to insert in the merge field. (WordWriter does not support other image formats.)
  5. Optional: Resize the image.
  6. Save the template.

If you are using a database as a data source, the column that corresponds to the merge field containing the image must be of type BLOB ("Image" in SQL Server). If the data source is an array of objects, the value that corresponds to the merge field containing the image should be a simple byte array.

For more information about different data sources see Using a Database as a Data Source and Using an Array as a Data Source.

New to v8.6.1 - the data type can be specified as either BLOB/byte array or as string file path to the image file on the server.

To specify how WordWriter should scale the image:

  1. Right-click the image and select Format Picture...
  2. Select the Size tab.
  3. Check or uncheck Lock aspect ratio.
  4. Check or uncheck Relative to original picture size .

Relative
to original
picture size

Lock aspect ratio

Meaning

false

false

The image will maintain its natural size and aspect ratio.

true

false

The image will be scaled to fit into the placeholder image but keep its natural aspect ratio.

false

true

The image will be scaled to fit into the placeholder image but keep its natural aspect ratio. The image will not be enlarged if it is smaller than the placeholder image.

true

true

The image will be scaled to fit into the placeholder image and its aspect ratio.

Using the Image Modifier

To insert an image in a merge field using the "image" modifier:

  1. Create or open a WordWriter template (for instructions, see Creating a WordWriter Template).
  2. Add the "image" modifier in parentheses to the merge field in which you want to insert the image. For example, change <<Product.Image>> to <<Product.Image(image)>>
  3. Optional: Set the "image" modifier's sizing arguments. For example, <<Product.Image(image(1,600,600))>> . The second and third parameters specify width and height, respectively, in twips. You can also use standard abbreviations to specify centimeters (cm), inches (in), or points (pt) when you use a template with the Office Open XML (.docx) format. The first argument tells WordWriter how to scale the image:

Value

Meaning

1

The image will always be the width and height specified regardless of its natural size.

2

The image will always be enlarged or shrunk to fit within the bounds specified by width and height but it will keep its natural aspect ratio.

3

The image will be scaled down to within the bounds specified by width and height but it will keep its natural aspect ratio.

If you are using a database as a data source, the column that corresponds to the merge field containing the image must be of type BLOB ("Image" in SQL Server). If the data source is an array of objects, the value that corresponds to the merge field containing the image should be a simple byte array.

New to v8.6.1 - the data type can be specified as either BLOB/byte array or as string file path to the image file on the server.

Sample Code

If you are using WordWriter v8.6.1, you can insert an image directly from a file.  The sample below shows how. 

Code Block
titleOfficeWriter v8.6.1 - Inserting an Image from a file
languagecsharp
WordTemplate wt = new WordTemplate();

//image from a file path
string newImage = @"C:\image.png";

//create a string array of field names.
//the field names must be the same as the merge field
//names in the template.
string[] arrfields = {"Product.Image(image1,600,600))"};

//create an object array of values
//ordinal numbers match those of the fields array
object[] arrvalues = {newImage};

//set the data source
wt.SetDataSource(arrvalues, arrfields, "ImageSource");

//process the data
wt.Process();

In earlier versions of WordWriter, the image must first be put into a byte array.

Code Block
titleInserting an Image from a byte array
languagecsharp
//create byte array from image
byte[] imgArray = File.ReadAllBytes(@"C:\image.png");

//create an object array of values
//ordinal numbers match those of the fields array
object[] arrvalues = {imgArray};

//create a string array of field names.
//the field names must be the same as the merge field
//names in the template.
string[] arrfields = {"Product.Image(image1,600,600))"};

//set the data source
wt.SetDataSource(arrvalues, arrfields, "ImageSource");

wt.Process();

For more sample code see the Insert Image Demo.