@SzuChiChen
Summary
The EQ field (the legacy “Equation” field that Word uses for the old Equation Editor) is not supported for rendering by Aspose.Words. When a document that contains such fields is saved as PDF, PNG, or any other raster/vector format, the field is left untouched and the result is the “garbled” image you are seeing.
The modern Office Math (OMML) equations that are created with Insert → Equation in recent versions of Word are rendered correctly, but the older EQ‑field based equations are outside the rendering engine’s capabilities.
Why your code does not help
Action you tried |
What it does |
Why it does not fix the problem |
document.UpdateFields() |
Updates the results of fields (e.g., TOC, DATE) but does not convert EQ fields to a displayable format. |
The EQ field still remains an unsupported field. |
Switching TextShaperFactory to HarfBuzz |
Affects only complex‑script text shaping (Arabic, Hindi, etc.). |
Equation rendering is unrelated to text shaping. |
GDI+ rendering |
Uses the same rendering pipeline as the PDF/PNG exporters. |
The pipeline still cannot draw EQ fields. |
What you can do
1. Convert the legacy EQ fields to Office Math (OMML) before handing the document to Aspose.Words
The only reliable way is to let Microsoft Word (or the Word automation COM object) perform the conversion, then save the resulting document and pass it to Aspose.Words.
// Example using Word Interop (run on a machine with MS Word installed)
var wordApp = new Microsoft.Office.Interop.Word.Application();
var doc = wordApp.Documents.Open(@"C:\input.docx");
// This command converts legacy equations to the new MathML format
doc.UpgradeLegacyMath();
doc.SaveAs2(@"C:\input_converted.docx", Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocument);
doc.Close();
wordApp.Quit();
// Now use Aspose.Words on the converted file
var asposeDoc = new Aspose.Words.Document(@"C:\input_converted.docx");
asposeDoc.Save(@"C:\output.pdf", SaveFormat.Pdf);
Note: UpgradeLegacyMath()
is available from Word 2010 onward. If you cannot use Word automation, you will need to ask the document creator to replace the old equations with the new “Insert → Equation” form.
2. Replace the EQ fields manually (if the number is small)
You can walk the document node tree, locate FieldType.FieldEq
and replace each field with a picture of the equation (generated, for example, by MathType or by rendering the field in Word and saving it as an image). Sample code snippet:
foreach (Field field in doc.Range.Fields)
{
if (field.Type == FieldType.FieldEq)
{
// Extract the field result (the rendered equation image) from Word beforehand,
// then replace the field with a Shape (Picture) node.
// This is a custom solution – Aspose.Words itself cannot render the EQ field.
}
}
3. Request a feature / file a bug
If you often receive documents that contain legacy EQ fields and cannot control their source, you may open a support ticket with Aspose. The team can log the limitation and, if there is sufficient demand, consider adding rendering support in a future release.
Official documentation
TL;DR
- EQ fields = not renderable by Aspose.Words (PDF/PNG/Image).
- Use Word (or Word automation) to upgrade those equations to the modern Office Math format before loading the document into Aspose.Words.
- After the upgrade, your existing code works perfectly – no need for HarfBuzz or special renderers.
If you need further assistance with the upgrade script or have any other Aspose.Words questions, feel free to let us know!