I see you had an example for an image from an SQL stream, but I would like to get the image from the file system, with the filename stored in an SQL field. In my query which populates all necessary info for the merge, one of the fields is called SignatureFilename (in pink below). How can I pass that field value to the HandleMergeImageFieldFromBlob function and put the SignaturefileName value were usernamehere.jpg (in green below) appears.
Hi
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your request. Please try using the following code example:
Document doc = new Document("in.doc");
// Perform several mail merge operations populating only part of the document each time.
// Use DataTable as a data source.
DataTable resultsTable = GetInfo();
// Add FieldMergingCallback. It is needed to insert images upon mail merge.
doc.MailMerge.FieldMergingCallback = new MergeImageField();
doc.MailMerge.ExecuteWithRegions(resultsTable);
doc.Save("out.doc");
private class MergeImageField : IFieldMergingCallback
{
void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)
{
// Do nothing.
}
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
{
string fileName = e.FieldValue.ToString();
e.ImageFileName = fileName;
}
}
private DataTable GetInfo()
{
// Create data table
DataTable table = new DataTable("Results");
table.Columns.Add("Description");
table.Columns.Add("Img");
// Add some dummy data.
table.Rows.Add(new object[] { "1", "C:\\Temp\\img1.jpg" });
table.Rows.Add(new object[] { "2", "C:\\Temp\\img2.jpg" });
table.Rows.Add(new object[] { "3", "C:\\Temp\\img3.jpg" });
return table;
}
The input and the output documents are attached.
Best regards,