Hello, I need to print barcode labels, sixteen for page, reading the barcode images created by Aspsose.Barcode and adding the product description below the barcode image. The final result should be one label for each product containing barcode image and product description. I’m thinking to proceed with the following steps:
- Creating a Word template for the labels
- Including two merge fields for each label, one for the barcode image and one for the product description
- Using MailMerge I will read from a DB table product description and image or retrieving image from a file
Would you mind sending me a snippet code about MailMerge or mailmerge with regions that is suitable with this scenario. Moreover, how should be configured the merge field in the word template to show the barcode image ({MERGEFIELD image:??} or what else) and how to control the size of the image?
Thank you for helping me.
Regards.
Luciano
Hi Luciano,
Thanks for your inquiry. To insert an image mail merge field into a document in Word, select Insert/Field command, then select MergeField and type **Image:**MyFieldName. Your image can be in the form of stream, bytes or file path. Please insert the mail merge fields with NEXT field in your input document as shown in attached image.
Please use following code example to achieve your requirements. We have attached sample template document with this post.
DataTable dt = new DataTable("Labels");
dt.Columns.Add("ProductName", typeof(String));
// If you are reading image from disk
// dt.Columns.Add("Barcode", typeof(String));
dt.Columns.Add("Barcode", typeof(Byte[]));
for (int i = 0; i < 20; i++)
{
DataRow dr = dt.NewRow();
dr["ProductName"] = "Aspose.Words";
// If you are reading image from disk
// dr["Barcode"] = MyDir + "image.jpg";
// image is in bytes
dr["Barcode"] = File.ReadAllBytes(MyDir + "image.jpg");
dt.Rows.Add(dr);
}
Document doc = new Document(MyDir + "MailingLabels.docx");
doc.MailMerge.Execute(dt);
doc.Save(MyDir + "Outv 16.4.0.docx");
Hi Tahir, I succeeded in printing labels merging data from db data table and building the images at run time.
Thank you so much for your precious help.
Have a nice day.
Luciano
Hi Luciano,
Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.