Hi Aspose support,
In our product we have functionality that converts equations’ content to images and replace OMathPara/OMath node with resulted image shape.
Similar to what MS Word do when converts DOCX document with equations into DOC/RTF format.
After testing this approach we were faced with different conversion issues, mainly incorrect/missed symbols, etc. in resulted image.
Please see the issues:
Case #1:
After conversion OMathPara/OMath node to EMF some symbols become double-stuck instead of letters from Keyboard in some equations.
Document: Equations from Office.com.zip (13.5 KB)
See results of conversion by Aspose and Word:
Page#1
Case#1Doc1Page1.png (48.6 KB)
Page#2
Case#1Doc1Page2.png (33.0 KB)
Document: Equations in Linear format Unicode.zip (11.5 KB)
Page#1
Case#1Doc2Page1.png (46.2 KB)
Document: Equations in Professional format.zip (12.1 KB)
Page#1
Case#1Doc3Page1.png (32.1 KB)
Document: Ink Equations.docx Ink Equations.zip (10.3 KB)
Page#1
Case#1Doc4Page1.png (17.7 KB)
Expected that conversion should work as in Word.
Case #2:
After conversion OMathPara/OMath node to EMF one row of equation is shifted to the right.
Document: Equations from Office.com.zip (13.5 KB)
See results of conversion by Aspose and Word:
Page#1
Case#2Page1.png (10.3 KB)
Expected that conversion should work as in Word.
Case #3:
After conversion OMathPara/OMath node to EMF spaces are missed in some equations.
Document: Equations from Office.com.zip (13.5 KB)
See results of conversion by Aspose and Word:
Page#2
Case#3Page2.png (55.2 KB)
Expected that conversion should work as in Word.
Case #4:
After conversion OMathPara/OMath node to EMF missed twelve arrows.
Document: Equations with non-math text.zip (10.1 KB)
See results of conversion by Aspose and Word:
Page#1
Case#4Page1.png (27.5 KB)
Expected that conversion should work as in Word.
Case #5:
After conversion OMathPara/OMath node to EMF sign of integral is missed in one equation.
Document: Ink Equations.zip (10.3 KB)
See results of conversion by Aspose and Word:
Page#1
Case#5Page1.png (13.6 KB)
Expected that conversion should work as in Word.
Case #6:
After conversion OMathPara/OMath node to EMF incorrect conversion of fields inserted into equations.
Document: Equations with different fields.zip (47.9 KB)
See results of conversion by Aspose and Word:
Page#1, 3
Case#6Page1.png (48.5 KB)
Expected that conversion should work as in Word.
Case #7:
After conversion OMathPara/OMath node to EMF some symbols inserted into equations are cropped.
Document: Equations with different symbols.zip (12.3 KB)
See results of conversion by Aspose and Word:
Page#1
Case#7Page1.png (36.5 KB)
Expected that conversion should work as in Word.
Case #8:
After conversion OMathPara/OMath node to EMF incorrect conversion of text with different effects inserted into equations.
Document: Equations with text with different languages and formatting.zip (15.6 KB)
See results of conversion by Aspose and Word:
Page#1
Case#8Page1.png (257.3 KB)
Expected that conversion should work as in Word.
Here is our code that perform conversion:
private void ReplaceFormulas(Document doc, ImageSaveOptions options, DocumentBuilder builder)
{
NodeCollection mathCollection = doc.GetChildNodes(NodeType.OfficeMath, true);
// Loop from last one to first one
for (int i = mathCollection.Count - 1; i >= 0; i--)
{
try
{
OfficeMath math = (OfficeMath)mathCollection[i];
// if node is MathPara or node is Inline Math with parent which is not Math Node, then replace with image
// Needs to differentiate inline and display formulas
if ((math.MathObjectType == MathObjectType.OMathPara) ||
((math.MathObjectType == MathObjectType.OMath) && (math.ParentNode?.NodeType != NodeType.OfficeMath)))
{
using (MemoryStream stream = new MemoryStream())
{
math.GetMathRenderer().Save(stream, options);
SizeF mathSize = math.GetMathRenderer().SizeInPoints;
builder.MoveTo(math);
Shape imageShape = builder.InsertImage(stream, mathSize.Width, mathSize.Height);
math.Remove();
}
}
}
catch
{
// Ignore exception and continue process math collection
}
}
}
The code which calls this method:
public void Replace()
{
try
{
// Save Equations into EMF format as optimal format for them
ImageSaveOptions optionsEmf = new ImageSaveOptions(SaveFormat.Emf);
optionsEmf.MetafileRenderingOptions.ScaleWmfFontsToMetafileSize = true;
optionsEmf.MetafileRenderingOptions.RenderingMode = MetafileRenderingMode.Vector;
optionsEmf.UseGdiEmfRenderer = false;
DocumentBuilder builder = new DocumentBuilder(_doc);
ReplaceFormulas(_doc, optionsEmf, builder);
}
catch (Exception e)
{
throw new DrawingReplacerException(e.Message);
}
}
Tested on Aspose.Words.dll v19.8.
Same issues happen and for PNG format, so looks like it does not matter what ImageSaveOptions are set.
Could you help with solving these problems?
Thanks in advance.