...
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 | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
//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