Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Mar 30, 2022 3:34 pm

I am using Spire.doc (from the spire.office package) to generate QR Codes in a document template with customURLs for a meeting. The field in the document: {MergeBarcode customURL QR \s 50} does not seem to be working.

The line of code I am using for the merge is :
Mailmerge.execute(datatable);

the field is showing up in the Document.fields list prior to the execution of the mailmerge under the object for Spire.doc.fields.field

The final document merges all the fields except the QR code. How can I get the QR codes to render from the data table of customURLs

traciemachi
 
Posts: 2
Joined: Wed May 23, 2018 4:21 pm

Wed Mar 30, 2022 11:41 pm

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

traciemachi
 
Posts: 2
Joined: Wed May 23, 2018 4:21 pm

Thu Mar 31, 2022 6:27 am

Hello,

Thank you for sharing the solution.
Glad to hear that the solution has been found by yourself.
If you encounter other issues related to our products in the future, please feel free to contact us. Wish you all the best!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1647
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc