Hi,
Hi Pit,
Hi,
Hi,
Thanks for your posting and using Aspose.Cells.
We are afraid there is no update for you 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 let you know asap.
Hi,
It has been 2 months…
Hi,
Thanks for your posting and using Aspose.Cells.
Please download and try the latest version: Aspose.Cells
for .NET v8.5.1.5 and see if it makes any difference and resolves your issue.
I have tested this issue with the following sample code using the latest version and the output emf image looks good. I have attached the emf image for your reference. Please remove its .txt extension after downloading it.
C#
var book = new Workbook(“Test.xlsx”);
Worksheet sheet = book.Worksheets[0];
var options = new ImageOrPrintOptions { HorizontalResolution = 300, VerticalResolution = 300, ImageFormat = ImageFormat.Emf };
var renderer = new SheetRender(sheet, options);
const string ImagePath = “out.emf”;
renderer.ToImage(0, ImagePath);
Hi,
The problem is when the image is then pasted into a Word document and converted to Pdf.
If you open the emf file in Inkscape and resave the file, the bug does not appear anymore when converting to PDF (with or without ‘text to path’ checked). So clearly Aspose is badly exporting to emf.
Hi John,
Thank you for testing the latest release of Aspose.Cells for .NET 8.5.2. Please note, the originally posted problem (CELLSNET-43732 Rendering to Emf and pasting into Word causes text overlapping in resultant PDF) is currently unresolved, and due to the complexity of the issue, we are taking much time to find a solution for it. Moreover, at the time of recording the defect, we used your provided code segment for verification. We also tested the case by generating the EMF with Aspose.Cells for .NET API and inserted in a word document manually to convert it to PDF format using MS Words. In this case the result is not correct as well.
Regarding Inkscape application, please allow me to install the application and confirm your claim to record my observations.
Hi again,
Hi John,
var book = new Workbook(“D:/Test.xlsx”);
Worksheet sheet = book.Worksheets[0];
var options = new ImageOrPrintOptions { HorizontalResolution = 300, VerticalResolution = 300 };
options.ImageFormat = ImageFormat.Emf;
var renderer = new SheetRender(sheet, options);
string ImagePath = “D:/out.emf”;
using (MemoryStream ms = new MemoryStream())
{
renderer.ToImage(0, ms);
ReSaveImageToEmfOnly(ms, ImagePath);
}
var doc = new Aspose.Words.Document();
var docBuilder = new Aspose.Words.DocumentBuilder(doc);
var image = Image.FromFile(ImagePath);
docBuilder.MoveToDocumentStart();
docBuilder.InsertImage(image);
doc.Save(“D:/out.pdf”);
static void ReSaveImageToEmfOnly(Stream srcStream, String destPath)
{
Bitmap dummyBitmap = null;
Graphics dummyGfx = null;
IntPtr hdc = IntPtr.Zero;
System.Drawing.Imaging.Metafile metafile = null;
try
{
dummyBitmap = new Bitmap(1, 1);
dummyGfx = Graphics.FromImage(dummyBitmap);
hdc = dummyGfx.GetHdc();
Image srcImage = Image.FromStream(srcStream);
Rectangle rect = new Rectangle(0, 0, srcImage.Width, srcImage.Height);
metafile = new System.Drawing.Imaging.Metafile(destPath, hdc, rect, System.Drawing.Imaging.MetafileFrameUnit.Pixel, EmfType.EmfOnly);
Graphics graphic = Graphics.FromImage(metafile);
graphic.DrawImage(srcImage, rect);
srcImage.Dispose();
graphic.Dispose();
}
finally
{
if (metafile != null)
{
metafile.Dispose();
}
if (hdc != IntPtr.Zero)
{
dummyGfx.ReleaseHdc(hdc);
}
if (dummyGfx != null)
{
dummyGfx.Dispose();
}
if (dummyBitmap != null)
{
dummyBitmap.Dispose();
}
}
}
Hi,
Hi,
Hi,
Hi,
Hi,
Hi John,
We can understand your situation, and we have already intimated the product team regarding your concerns by increasing the priority of the said ticket to Critical. We have also requested them to share alternative approach as you have rejected the conversion of Aspose.Cells’ generated EMF to EmfOnly format. As soon as we get more updates in this regard, we will post here for your kind reference.
Hi again,
This is to inform you that we have done further research on the presented scenario. Please note, we have used the plain .NET APIs to generate two EmfPlusDual files by changing the PageUnit to Pixels and Points. We have noticed that both resultant EMF files look the same when viewed in the image viewers such as Microsoft Office Picture Manager and Paint application. However, when inserted in a Document file and converted to PDF (manually with Office 2010 and using Aspose.Words APIs) we have noticed that there are problems with the image generated with PageUnit as Point, such as the location of text seems to be wrong when document is converted with Office 2010. When we used the Aspose.Words APIs to generate the PDF, the location of the text seems to be correct but the font size is different. Please check the attachment for all the files used/generated for this test case.
C#
Bitmap dummyBitmap = null;
Graphics dummyGfx = null;
System.IntPtr hdc = IntPtr.Zero;
System.Drawing.Imaging.Metafile metafile = null;
int width = 200;
int height = 200;
//in pixels
float loc = 34;
PointF p1, p2;
try
{
dummyBitmap = new Bitmap(1, 1);
dummyGfx = Graphics.FromImage(dummyBitmap);
hdc = dummyGfx.GetHdc();
metafile = new System.Drawing.Imaging.Metafile(imagePath, hdc, new RectangleF(0, 0, width, height), MetafileFrameUnit.Pixel, EmfType.EmfPlusDual);
Graphics mGr = Graphics.FromImage(metafile);
mGr.Clear(Color.White);
mGr.PageUnit = pageUnit;
p1 = new PointF(50, 100);
p2 = new PointF(50 + loc, 100);
if (mGr.PageUnit == GraphicsUnit.Point)
{
//pixel to point
p1 = new PointF(p1.X * 72 / mGr.DpiX, p1.Y * 72 / mGr.DpiX);
p2 = new PointF(p2.X * 72 / mGr.DpiX, p2.Y * 72 / mGr.DpiX);
}
System.Drawing.Font font = new System.Drawing.Font(“Arial”, 11);
Brush brush = new SolidBrush(Color.Red);
mGr.DrawString(“Test”, font, brush, p1);
mGr.DrawString(“Test”, font, brush, p2);
mGr.Dispose();
}
finally
{
if (metafile != null)
{
metafile.Dispose();
}
if (hdc != IntPtr.Zero)
{
dummyGfx.ReleaseHdc(hdc);
}
if (dummyGfx != null)
{
dummyGfx.Dispose();
}
if (dummyBitmap != null)
{
dummyBitmap.Dispose();
}
}
Hi,
Hi John,
Thanks for your posting and using Aspose.Cells.
We are very sorry to say that there is no further update for you. However, we have logged your comment in our database against this issue and requested the product team to provide you some ETA or fix for this issue. We are hopeful you will hear some good news soon. Please pardon us for delays as we have been working on lots of customer issues lately. Have a good day and cheers.
Hi,
Thanks for using Aspose.Cells.
As we posted in https://forum.aspose.com/t/41172 , please try to turn to Aspose Word product to see if they can have some progress.
<br><br>