I’m experiencing a rendering issue where Field Code content with font unerlines does not display correctly.
To help reproduce the problem, I have prepared the following:
Sample Code:
using Aspose.Words;
using Aspose.Words.Saving;
using Aspose.Words.Shaping.HarfBuzz;
var license = new License();
license.SetLicense(@"licensePath");
var document = new Document(@"inputDocxPath");
// document.UpdateFields();
var pngSaveOptions = new ImageSaveOptions(SaveFormat.Png)
{
// MetafileRenderingOptions =
// {
// RenderingMode = MetafileRenderingMode.VectorWithFallback,
// EmulateRasterOperations = false
// }
};
document.Save(@"outputPngPath", pngSaveOptions);
Sample Docx:
fieldCode_underLine.docx (16.3 KB)
Aspose Result:
Expeceted Result:
Environment:
- .NET Framework 4.8
- Aspose.Words 25.9.0
- Aspose.Words.Shaping.HarfBuzz 25.9.0
@SzuChiChen
The issue you’re experiencing with the missing underline in field codes when converting a DOCX to PNG may be related to how Aspose.Words handles the rendering of field codes. To address this, you can try the following steps:
-
Update Fields: Ensure that you are updating the fields in the document before saving it. Make sure to include the line document.UpdateFields();
in your code to ensure all fields are updated.
-
Use Metafile Rendering Options: You can experiment with the MetafileRenderingOptions
to improve the rendering of underlined text. Here’s how you can modify your pngSaveOptions
:
var pngSaveOptions = new ImageSaveOptions(SaveFormat.Png)
{
MetafileRenderingOptions = new MetafileRenderingOptions
{
RenderingMode = MetafileRenderingMode.VectorWithFallback,
EmulateRasterOperations = false
}
};
-
Check Font Availability: Ensure that the font used for the field codes is available on the system where the conversion is taking place. If the font is missing, it may lead to rendering issues.
-
Test with Different Formats: If the issue persists, consider converting the document to PDF first and then to PNG, as PDF rendering may preserve the formatting better.
Here’s the modified code snippet:
using Aspose.Words;
using Aspose.Words.Saving;
var license = new License();
license.SetLicense(@"licensePath");
var document = new Document(@"inputDocxPath");
document.UpdateFields(); // Ensure fields are updated
var pngSaveOptions = new ImageSaveOptions(SaveFormat.Png)
{
MetafileRenderingOptions = new MetafileRenderingOptions
{
RenderingMode = MetafileRenderingMode.VectorWithFallback,
EmulateRasterOperations = false
}
};
document.Save(@"outputPngPath", pngSaveOptions);
By following these steps, you should be able to improve the rendering of field codes with underlines in your output PNG. If the problem continues, consider reaching out to Aspose support for further assistance.
The underline is still missing in vector mode, even after trying UpdateFields()
and re-rendering. The result is the same.
@SzuChiChen
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-28687
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.