I am upgrading aspose.word for java to the latest version.
I get a problem about font.
I have a lot of existing word template. And after the templates are merged, doc files are generated, I find that the first symble of a lot of words looks smaller than the symber behind it.
For example, for '06/01/2011’ which is a merged value, font size of ‘06’ looks smaller than ‘06/01/2011’. Font size of ‘06’ is 8, font style is ‘Arial’, but font size of ‘06/01/2011’ is bigger and font style is ‘Times New Roman’.
This article gives three workarounds.
Method 1: Add the Charformat Switch. Edit the merge field and add the Charformat switch.
Method 2: Change the Normal Style. You can modify the built-in Normal style to match the font that you want.
Method 3: Merge to a New Document and Make Formatting Changes
These workarounds only for word. I have a lot of templates to handle. It’s impossible for me to do this mannually. Could you please tell me to change the normal style in runtime? I prefer method 2. Or you have other way to solve this problems?
Maybe you can read this article in support center of Microsoft.
Moreover, to change merge field style and formatting, please see the following sample implementation of IFieldMergingCallback.FieldMerging event:
private class HandleMergeFieldAlternatingRows : IFieldMergingCallback
{
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
if (mBuilder == null)
mBuilder = new DocumentBuilder(e.Document);
if (e.FieldName.Equals("yourDateFieldName"))
{
mBuilder.MoveToMergeField(e.FieldName);
mBuilder.Font.StyleIdentifier = StyleIdentifier.DefaultParagraphFont;
Run run = new Run(mBuilder.Document);
run.Text = e.FieldValue.ToString();
// You can set font here
Aspose.Words.Font font = run.Font;
font.Bold = true;
font.Color = Color.Red;
mBuilder.InsertNode(run);
}
}
public void ImageFieldMerging(ImageFieldMergingArgs args)
{
throw new NotImplementedException();
}
private DocumentBuilder mBuilder;
}
In addition to my previous reply, please note that the formatting of merge fields, upon Mail Merge execution, should be preserved and that is not happening in your case. Could you please attach your template document here for testing? We will investigate and try to reproduce this issue on on our side and then provide you more information.
Thanks for your answer. But I think you misunderstood me.
The style is
defined in word file. For the same field, in different file, its style
is different. The style is defined by user, but not set in runtime.
Hello
Thanks for your inquiry. ‘mBuilder.Font.Name’ it is font of FieldName. Please press Alt-F9 to see the field code. As you can see FieldName->Arial, FieldCode and FieldSeparator->TimesNewRoman. Actually it is the reason of the problem.
Best regards,
Hi,
I run into this issue again when I am working on the same project of evaluating the upgrading Aspose word for Java from 2.4.1 to 11.5.0 that Shaohui worked on before.
I have two questions:
Q1: Does this is a regression? For the same template, it can be generated correct word in version 2.4.1 but this issue will happen in v11.5.0.
Q2: Is there some global setting to control this behavior instead of using FieldMergeCallback?
In our template, there are hundreds merge field and the leading words in those merge fields are smaller then the following words just as the previous description Shaohui wrote. So it is hard to use the if-else statement to adjust all merge fields Font. I am concerning about this approachs performance. If the output word has more then 50 pages, the performance may have serious degradation with this field by field font adjustment.
I am looking forward to your reply since this is very important for me to decide when and how to upgrade our Aspose component to latest version.
The problem is part of the merged field using the font of "FieldName"
and part of the merged field using the font of Normal style.
For example:
“United States” is the value of Country with font Arial 9. You can see the “United” is rendered correctly but the “States” is wrong, the font is “Times New Roman 12”.
Hope anyone from Aspose can check if this is regression defect.
While using the latest version of Aspose.Words i.e. 11.5.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system as a regression. The issue ID is WORDSNET-6674. Your request has been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.
Thanks for your inquiry. Unfortunately, your issue is not resolved yet. Our development team is currently doing analysis of this issue. We will inform you as soon as your issue is resolved.
Could you confirm that this issue has been fixed and no regression on 13.2.0?
From our testing result, we found that this issue still exist in Aspose.Word 13.2.0
And I know new Run set Font can resolve this issue, but it will cost a lot of memory from our observation since we have large number of records during mailmerge. And moveToMergeField and new Font will cost a lot of memory consumption.
Hi Guilin,
Thanks for your inquiry. Yes, the fix to WORDSNET-6674 was integrated in Aspose.Words 11.7.0. However, to ensure a timely and accurate response please supply us with the following information, if you cannot supply us with this information we will not be able to investigate your issue and raise a ticket.
What version of Aspose.Words for Java are you using?
What environment are you running on?
OS (Windows Version or Linux Version)
Architecture (32 / 64 bit)
MS Office Version
Any Third Party Libraries / SDK in addition to Aspose Products
Please supply us with the code from your application that is causing the issue
Please supply us with the input document that is causing the issue
Please supply us with the output document showing the undesired behavior
As soon as you get these pieces of information to us we’ll start our investigation into your issue.
Many thanks,