Barcode font not rendering in Mailmerge

Hi, I can’t seem to mailmerge and render it using a free barcode font. I have tried embedding the font in the word doc.

If I put some non-mail-merged text in and set it to be the barcode font, it prints fine.

Can you help, I attach my mailmerge docx.

G

Hi,

I have generated a PDF file using Aspose.Words for .NET 16.12.0 and the following code and attached it here for your reference:

private static DataTable GetDataTable()
{
    DataTable dataTable = new DataTable("Invitations");
    dataTable.Columns.Add(new DataColumn("Id"));
    DataRow dataRow;
    dataRow = dataTable.NewRow();
    dataRow[0] = "Some ID";
    dataTable.Rows.Add(dataRow);
    return dataTable;
}
Document doc = new Document(MyDir + @"BarcodeTemplate1.docx");
doc.MailMerge.ExecuteWithRegions(GetDataTable());
doc.Save(MyDir + @"16.12.0.pdf");

Do you see the same problems when generating/printing to PDF on your end? If not please create a comparison screenshot highlighting (encircle) the problematic areas in PDFs and attach it here for our reference. We will investigate the issue further on our end and provide you more information.

Also, please attach your expected PDF document showing the correct output here for our reference. You may create expected document using Microsoft Word.

Best regards,

Hi, I have tried using your code (and upgraded to 16.12.1.0) and the same issue occurs.

I modified your code from:

dataRow[0] = "Some ID";

to

dataRow[0] = "123456";

and executed it using the attached docx and as you can see in the pdf, the number is not in a barcode font.

Hi,

You need to assign a single font name to all run nodes inside merge field. Please try using the following code:

Document doc = new Document(MyDir + @"BarcodeTemplate1.docx");
foreach (Field field in doc.Range.Fields)
{
    if (field.Type.Equals(FieldType.FieldMergeField))
    {
        Node currentNode = field.Start;
        bool isContinue = true;
        while (currentNode != null && isContinue)
        {
            if (currentNode.NodeType.Equals(NodeType.FieldEnd))
                isContinue = false;
            if (currentNode.NodeType.Equals(NodeType.Run))
            {
                ((Run)currentNode).Font.Name = "Free 3 of 9";
            }
            Node nextNode = currentNode.NextPreOrder(currentNode.Document);
            currentNode = nextNode;
        }
    }
}
doc.MailMerge.ExecuteWithRegions(GetDataTable());
doc.Save(MyDir + @"16.12.0.pdf");

Hope, this helps.

Best regards,

Hi, this sets every merge field in the document to the barcode font; I only want a single merge field to be in this font, leaving other fields to be other fonts. Whilst I can hard code it if you can point me to how I can inspect the MergeField name, it’s not exactly ideal.

Is this not a bug? Shouldn’t the merge logic just honour the font that the MergeField is set to?

G

Hi,

Thanks for your inquiry. I am afraid, this does not look like a bug in Aspose.Words. The problem occurs because not all Run nodes of merge fields are formatted with barcode font. You can check if any Run node of merge field has barcode font applied to it, if yes then format all run nodes of that merge field are formatted with barcode font. Please use the following code:

Document doc = new Document(MyDir + @"BarcodeTemplate1.docx");
ArrayList mfs = new ArrayList();
// Determine what fields have barcod font applied to at least one Run
foreach (Field field in doc.Range.Fields)
{
    if (field.Type.Equals(FieldType.FieldMergeField))
    {
        Node currentNode = field.Start;
        bool isContinue = true;
        while (currentNode != null && isContinue)
        {
            if (currentNode.NodeType.Equals(NodeType.FieldEnd))
                isContinue = false;
            if (currentNode.NodeType.Equals(NodeType.Run))
            {
                if (((Run)currentNode).Font.Name == "Free 3 of 9")
                {
                    mfs.Add(field);
                    break;
                }
            }
            Node nextNode = currentNode.NextPreOrder(currentNode.Document);
            currentNode = nextNode;
        }
    }
}
// Apply barcode font to all Run nodes inside those merge field
foreach (Field field in mfs)
{
    if (field.Type.Equals(FieldType.FieldMergeField))
    {
        Node currentNode = field.Start;
        bool isContinue = true;
        while (currentNode != null && isContinue)
        {
            if (currentNode.NodeType.Equals(NodeType.FieldEnd))
                isContinue = false;
            if (currentNode.NodeType.Equals(NodeType.Run))
            {
                ((Run)currentNode).Font.Name = "Free 3 of 9";
            }
            Node nextNode = currentNode.NextPreOrder(currentNode.Document);
            currentNode = nextNode;
        }
    }
}
doc.MailMerge.ExecuteWithRegions(GetDataTable());
doc.Save(MyDir + @"16.12.0.pdf");

Hope, this helps.

Best regards,