@akondewar Please try saving the output document as DOCX and make sure the DISPLAYBARCODE field is there in the output document. Also, please try setting barcode generator before executing mail merge:
@alexey.noskov
Hi ,
While using suggested code, we are facing another issue that is, at least one character is required before "{IF {MERGEFIELD displaybarcode }="true" {DISPLAYBARCODE "{MERGEFIELD WOBarcode \*MERGEFORMAT }" s:CODE128-w:13\h 300\t\* MERGEFORMAT}" {MERGEFIELD WOBarcode \*MERGEFORMAT}}" in the header section.
If we removed character before above condition then Barcode is not printed.
@akondewar It is required to accurately format the fields in the template to get the correct result. There must be whitespaces before and after condition operator in the IF field, there must be whitespaces between true and false values. If the values in the IF field have whitespaces they must be enclosed into double quotes.
If the field is formatted improperly, it cannot be parsed properly by both MS Word and Aspose.Words. You can save the output as MS Word document to make sure the resulting field is formatted properly and can be properly updated by MS Word.
@akondewar I see that your document has bad formatted IF fields. I have created a simplified bad input document: bad.docx (27.0 KB) bad_out.docx (21.9 KB)
The problem can be reproduced using the following code:
Document doc = new Document("C:\\Temp\\bad.docx");
doc.getMailMerge().deleteFields();
doc.updateFields();
doc.save("C:\\Temp\\out.docx");
If field should always contain true and false values, in your case false value is missed. Here is the corrected document: in.docx (27.0 KB) out.docx (21.9 KB)
@akondewar In your code there is no code that removes the the empty region table title row. The same there is not IF field condition in your template the will hide it. So it is expected that the table header remains in the output.
@akondewar You can simply remover tables with a single row. The region in your template occupies the second row, which is removed upon executing mail merge. So you can use code like this to remove a lonely row tables:
for(Table t : (Iterable<Table>)doc.getChildNodes(NodeType.TABLE, true))
{
if(t.getRows().getCount()==1)
t.remove();
}
@akondewar To render bullet symbol MS Word as well as Aspose.Words uses Symbol font. It looks like the font is not available in the environment where the document is converted to PDF.
To build an accurate document layout the fonts are required. If Aspose.Words cannot find the fonts used in the document the fonts are substituted . This might lead into the layout and appearance difference. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you: https://docs.aspose.com/words/java/specify-truetype-fonts-location/ https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/
Please try either installing or providing the fonts required to render the document. This should resolve the problem.
Hi @alexey.noskov
We are using multiple custom templates, we never know the Mergefeild Table name. So we can not used hardcore MergeField Table name in our code. It is our common code.
Please provide generic solution that will not impact on existing templates.