We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mail merge with Code39 font

Hi,
I am using Aspose.Words mail merge and Code39 font to render barcodes into my documents.
This only works when the text to merge has a leading space. Otherwise the text will be written in “Times New Roman”.
I attached a sample console project to reproduce which contains a sample document, the fonts .ttf file and the generated output.
I used latest Aspose.Words version (14.4.0.0).

Kind regards

Hi Christian,

Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 14.4.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-10161. Your thread has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Hi Christian,


Thanks for being patient. Regarding WORDSNET-10161, our development team has completed the work on your issue and has come to a conclusion that they won’t be able to implement the fix to your issue. Your issue (WORDSNET-10161) is now closed with ‘Won’t Fix’ resolution.

The problematic merge field contains MERGEFORMAT switch and its old “result” contains following three runs:

<w:r w:rsidRPr=“00ED1E0A”>
 <w:rPr>
<w:rFonts w:ascii=“Times New Roman” w:hAnsi=“Times New Roman” w:cs=“Times New Roman”/>
<w:noProof/>
</w:rPr>
<w:t>«</w:t>
</w:r>
<w:r w:rsidRPr=“00ED1E0A”>
<w:rPr>
<w:rFonts w:ascii=“Code39MHr” w:hAnsi=“Code39MHr”/>
<w:noProof/>
</w:rPr>
<w:t>Barcode_1</w:t>
</w:r>
<w:r w:rsidRPr=“00ED1E0A”>
<w:rPr>
<w:rFonts w:ascii=“Times New Roman” w:hAnsi=“Times New Roman” w:cs=“Times New Roman”/>
<w:noProof/>
</w:rPr>
<w:t>»</w:t>
</w:r>

Because field contains switch “MERGEFORMAT”, Aspose.Words merges formats from old result nodes to new result nodes. To exclude formatting with font “Times New Roman” you may select all old field result (for example “«Barcode_1»” and choose font Code39). You can modify template by using Microsoft Word or use the following code before executing mail merge:

Document doc = new
Document(MyDir + @“MergeFieldsCode39.docx”);

foreach (Field field in doc.Range.Fields)

{

if (field.GetFieldCode().Contains("\\* MERGEFORMAT"))

{

Node currentNode = field.Separator;

bool flag = true;

while (currentNode != null && flag)

{

if (currentNode.NodeType == NodeType.FieldEnd)

flag = false;

Node nextNode = currentNode.NextPreOrder(currentNode.Document);

if (currentNode.NodeType == NodeType.Run)

{

Run run = (Run)currentNode;

run.Font.Name = "Code39MHr";

}

currentNode = nextNode;

}

}

}

// the merge fields in document

List<string> fields = new List<string> {

"Barcode_1",

"Barcode_2",

"Barcode_3" };

// the merge data

List<object> fieldsdata = new List<object> {

"NoSpace",

" LeadingSpace",

"Just some more Words" };

// do mail merge

doc.MailMerge.Execute(fields.ToArray(), fieldsdata.ToArray());

doc.Save(MyDir + @“out-fixed.docx”);


I hope, this helps.

Best regards,