Free Support Forum -

Mege with barcode


I have a problem with creating a PDF document using Word and XML.

The word document contains a mergefield in “Code 128” font. In the XML file, the field which I want to merge is like “123456//”, with two slashes at the end.

When I do the merge with Aspose.Words (v 11.5), the result is a barcode for the first numbers, but the slashes are still not “barcodded”.

All the files are included in this post : .doc, …xml and the generated pdf. The doc has twice the mergefield : one in a classic fonf, the other in barcode font.

Thanks for your help.

Hi Daniel,

Thanks for your inquiry. It would be great if you please share the font “Code 128” here for testing purposes. I suggest you to use latest version of Aspose.Words for Java v 11.10.0. You may use IFieldMergingCallback to achieve your requirement.

<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document(MYDir

  • “Test80.doc”);<o:p></o:p>

String[] fieldNames = new String[] { "codebarre" };

Object[] fieldValues = new Object[] { "30895018//" };

doc.getMailMerge().setFieldMergingCallback(new FontSetting());

doc.getMailMerge().execute(fieldNames, fieldValues); + "AsposeOut.pdf");

public class FontSetting implements IFieldMergingCallback {

private DocumentBuilder mBuilder;

public void fieldMerging(FieldMergingArgs e) throws Exception {

if (mBuilder == null) {

mBuilder = new DocumentBuilder(e.getDocument());


if (e.getFieldName().equals("codebarre")) {



mBuilder.getFont().setName("Code 128");





public void imageFieldMerging(ImageFieldMergingArgs args) throws Exception {




Here is the ttf.

For your information, I use the “XmlMailMergeDataTable” to merge the fields with the XML.

Thanks for your help.

Hi Daniel,

Thanks for sharing the details. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-7417 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Daniel,

Thanks for your patience. Our development team has investigated this issue and shared that this is not an issue. Please note that Aspose.Words tries to mimic the same behavior as MS Word do. If you do the mail merge by using MS Word with shared documents, you will get the same output.

Please do not use * MERGEFORMAT” switch in conjunction with a barcode font. Please use the merge field as shown below:

{ MERGEFIELD codebarre }

I have attached the modified input document and output document with this post. Please let us know if you have any more queries.