Excel To PDF Incorrect Emf Conversion

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”);

Pdf output is incorrect.

Excel and Pdf document int the attachment files.

Hi,


Thanks for providing us template files.

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.

Thank you.

Hi,


We have fixed your issue “CELLSNET-44495” now. We will soon provide the fix after performing QA and incorporating other enhancements and fixes.

Thank you.

Hi,


Please try our latest version/fix: Aspose.Cells for .NET v8.8.2.5 (attached).

It fixes your issue now.

Let us know your feedback.

Thank you.

Hi,

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.

Hi,


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.

Thank you.

Hi,

Thanks for using Aspose.Cells.

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.

Will or when will the problem with Aspose.Cells APIs be fixed?

Hi,

Thanks for your posting and using Aspose.Cells.

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.

Hi,


Thanks for using Aspose.Cells.

We are afraid, we are unable to resolve this issue after much investigation and now we have no plans to fix it.

@mrcook, @mhavdio

It works OK with our lastest version v23.2(Download | Nuget).
Code:

Workbook workbook = new Workbook("test (1).xlsx");

PdfSaveOptions saveOptions= new PdfSaveOptions();
saveOptions.EmfRenderSetting = EmfRenderSetting.EmfPlusPrefer;

workbook.Save("output.pdf", saveOptions);