I am using Aspose.Word to create a EMF file from MathML.
The post here:
explains how to do this.
Then, I add this image into Worksheet:
var mathMl =
@"<math xmlns="“http://www.w3.org/1998/Math/MathML”">y=a+bx+cx2+dx3+ex4";
var doc = new Document();
var builder = new DocumentBuilder(doc);
builder.InsertHtml(mathMl);
OfficeMath math = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true);
var options = new ImageSaveOptions(SaveFormat.Emf)
{
Resolution = 200
};
var workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
using (var imageStream = new MemoryStream())
{
math.GetMathRenderer().Save(imageStream, options);
worksheet.Pictures.Add(1, 1, imageStream);
}
var pdfSaveOption = new Aspose.Cells.PdfSaveOptions();
workbook.Save(“test.pdf”, pdfSaveOption);
Process.Start(“test.pdf”);
workbook.Save(“test.xlsx”, Aspose.Cells.SaveFormat.Xlsx);
Process.Start(“test.xlsx”);
After an initial test, I observed the issue as you mentioned. I found an incorrect EMF image conversion in the rendered PDF file by Aspose.Cells APIs. I simply convert your attached template Excel file to PDF, the rendered image in the output PDF is wrong as per your attached PDF file.
e.g Sample code:
var book = new Workbook(“e:\test2\test.xlsx”); book.Save(“e:\test2\out1.pdf”);
I have logged a ticket with an id “CELLSNET-44495” for your issue. We will look into your issue soon.
Once we have an update on it, we will let you know here.
Thanks for your fix, it works much better now but still there is problems.
Here is an example:
var mathMl1 =
@"<math xmlns="“http://www.w3.org/1998/Math/MathML”">y=d+a-d<mfenced open=""["" close=""]"" separators=""|"">1+<mfenced separators=""|"">xcbm";
var mathMl2 =
@"<math xmlns="“http://www.w3.org/1998/Math/MathML”">y=d+a-d1+<mfenced separators=""|"">xcb";
var mathMl3 =
@"<math xmlns="“http://www.w3.org/1998/Math/MathML”">y=a e<mfenced separators=""|"">-<mfenced separators=""|"">x-b2c22";
var equations = new[] {mathMl1, mathMl2, mathMl3};
var doc = new Document();
var builder = new DocumentBuilder(doc);
var workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
for (int i = 0; i < equations.Length; i++)
{
builder.InsertHtml(equations[i]);
OfficeMath math = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true);
var options = new ImageSaveOptions(SaveFormat.Emf)
{
Resolution = 200
};
using (var imageStream = new MemoryStream())
{
math.GetMathRenderer().Save(imageStream, options);
worksheet.Pictures.Add(1 + i*3, 1, imageStream);
}
math.Remove();
}
var pdfSaveOption = new Aspose.Cells.PdfSaveOptions();
workbook.Save(“test.pdf”, pdfSaveOption);
Process.Start(“test.pdf”);
workbook.Save(“test.xlsx”, Aspose.Cells.SaveFormat.Xlsx);
Process.Start(“test.xlsx”);
I have attached output files.
First problem is with pdf output. You can see in the attached file that braces is overlapping with variables. In the third equation right brace is cutted.
Second problem is with EMF created by Word engine.
Power of (x-b)^2 (third equation) is generated wrong. I have attached word document with expected equation.
Thanks for your template files and further details.
I have evaluated your scenario/ case again, I tested with your newly attached template Excel file to simply convert to PDF by Aspose.Cells APIs and found the issue. In the output PDF file, the braces are overlapping with variables and the third equation’s right brace is cut too. I have reopened your issue “CELLSNET-44495” again. Our concerned developer from product team will look into it soon.
Regarding your second problem (i.e., “EMF created by Word engine”), since this looks to me a possible issue in Aspose.Words APIs, so kindly post your issue with all the details and samples in Aspose.Words forum. One of my fellow colleagues from Aspose.Words team will evaluate your issue and help you through there.
The three emf files (see attachment) in the source file are EmfPlusDual type. There are both Emf and EmfPlus records. We only render Emf records now. If you open the image files in an image viewer that only support Emf records (like IrfanView image viewer), you will find the images are similar to that we render to pdf.
We are afraid there is no update for you at this moment regarding this issue. However, we have logged your comment in our database against this issue and requested the product team to provide some fix or ETA for this issue. Once there is some news for you, we will update you asap by posting in this thread.