Managed to solve this issue with a workaround, in case anyone is looking for answers here.
Use case: print a sheet of unique customURLs in QR code for each customer.
Started with the Avery 22805 template; added mergefield for CustomURL and Mergefield for Name, then all boxes except the last one have a "next record". saved the file as the Source file.
- Code: Select all
string SrcFile = @"..\Avery22805PrinttotheEdgeSquareLabels.dotx";
System.Data.DataTable dt = //get a datatable of CustomURL and Name for the mail merge
Spire.Doc.Document document = new Spire.Doc.Document();
document.LoadFromFile(SrcFile);
document.MailMerge.Execute(dt);
// now replace each CustomURL with its QR Code
foreach (System.Data.DataRow dr in dt.Rows) {
Spire.Doc.Documents.TextSelection ts = document.FindString(dr["CustomURL"].ToString(), false, false);
Spire.Barcode.BarcodeSettings bs = new Spire.Barcode.BarcodeSettings();
bs.Type = Spire.Barcode.BarCodeType.QRCode;
bs.QRCodeECL = Spire.Barcode.QRCodeECL.M;
bs.X = 0.7f; // default = 0.6
bs.Data = dr["CustomURL"].ToString();
bs.Data2D = dr["CustomURL"].ToString();
bs.ShowText = false;
Spire.Barcode.BarCodeGenerator bg = new Spire.Barcode.BarCodeGenerator(bs);
Spire.Doc.Fields.DocPicture pic = new Spire.Doc.Fields.DocPicture(document);
pic.LoadImage( bg.GenerateImage());
Spire.Doc.Fields.TextRange r = ts.GetAsOneRange();
int index = r.OwnerParagraph.ChildObjects.IndexOf(r);
r.OwnerParagraph.ChildObjects.Insert(index, pic);
r.OwnerParagraph.ChildObjects.Remove(r);
}
// save to stream or file for delivery
Not as pretty as using field: {MergeBarcode customURL QR \s 50} in manual word mailmerge