2237_Source.docx (20.6 KB)
2237_Development_withMergeFieldsFilledIn.docx (20.3 KB)
Could anyone explain why the latest version of aspose, being used by the code shown below, would produce an output where only some of the contents of the merged values as bold? When we were using an older version 11 of aspose with very similar merge field code, the entire contents of the merge values were bolded.
Code that we use to merge fields into word docs:
private async Task MergeWordDocument(DocumentClass lwDoc, MailMergeDataSource mergeInfo)
{
var lwobjs = _context.Loan.LWObjects;
var doc = new Document(lwDoc.SourceFileName);
mergeInfo.MoveFirst();
mergeInfo.SetCurrentDocument(lwDoc);
DocumentBuilder builder = new(doc);
await BuildDocument(lwDoc, builder, lwobjs, mergeInfo);
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs | MailMergeCleanupOptions.RemoveUnusedFields; //This is the fix for empty merge fields leaving extra line feeds!
doc.MailMerge.Execute(mergeInfo);
FontSettings.DefaultInstance.SubstitutionSettings.FontInfoSubstitution.Enabled = true;
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("MissingFont", "Arial");
var wordDebugFile = _tempFileService.CachePath + lwDoc.DocId + ".Docx";
doc.Save(wordDebugFile, SaveFormat.Docx);
var options = new PdfSaveOptions
{
//EmbedFullFonts = true,
//UseCoreFonts = false,
PreserveFormFields = true,
SaveFormat = SaveFormat.Pdf,
Compliance = PdfCompliance.Pdf17, // or PdfA1a for archival
//ExportDocumentStructure = true
};
doc.Save(lwDoc.TempFileName, options);
@bribiesca
It sounds like you’re experiencing an issue where only some of the merged content is appearing bold in the output document, while it was fully bold in the previous version of Aspose. This could be due to changes in how the newer version handles font styles during the mail merge process.
Cause: The issue may stem from the source document’s styles, font settings in your code, or changes in the Aspose version regarding mail merge and font handling.
Solution: Here are a few steps you can take to troubleshoot and potentially resolve this issue:
-
Check the Source Document: Ensure that the source document (the one you’re merging into) has the correct styles applied to the merge fields. If the merge fields are set to a specific style that does not include bold formatting, this could affect the output.
-
Font Settings: Review the font settings in your code. You have a line that enables font substitution, which might be affecting how fonts are rendered. Make sure that the font you are substituting (e.g., “MissingFont” to “Arial”) is not causing the bold formatting to be lost.
-
Mail Merge Options: Consider adjusting the MailMergeCleanupOptions. While you are already using some cleanup options, you might want to experiment with different settings to see if they impact the formatting.
-
Test with a Simple Document: Create a simple test document with a few merge fields and apply bold formatting to them. Run the merge process to see if the issue persists. This can help isolate whether the problem is with the specific documents you are using or with the code itself.
-
Review Release Notes: Check the release notes for the version of Aspose you are using to see if there are any known issues or changes related to mail merge and font handling.
Here’s a minimal code snippet to ensure that the merge fields are bold:
builder.Font.Bold = true; // Set the font to bold before executing the merge
doc.MailMerge.Execute(mergeInfo);
Next Steps: Please try the above steps and let me know if they help resolve the issue. If the problem persists, provide any additional details about your setup, and I will assist you further. Thank you!
We have tried those things. I have given steps in the original message
@bribiesca
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-28558
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@bribiesca We have completed analyzing the issue and conclude it is not a bug. Here is MS Word Mail Merge output simplified_out.docx (9.8 KB).
The sample document contains the MERGEFIELD field with the MERGEFORMAT switch. Current field result 98 is marked as bold, but the field itself is not. When MERGEFORMAT is applied to the new field result Loan # 1225184205 MS Word copies formatting from the old result word by word and leaves unpaired words with default formatting.
To ensure excepted result (the whole field result to be bold) the whole field has to be bold.