Emf produced has unselectable text in Word Pdf

Hi,

Running the following code on a simple Excel file with some text in a Cell:

        var book = new Workbook("test.xlsx");
        Worksheet sheet = book.Worksheets[0];
        var options = new ImageOrPrintOptions
        {
            ImageFormat = ImageFormat.Emf,
            OnePagePerSheet = true,

        };
        new SheetRender(sheet, options).ToImage(0, "test.emf");

If you copy this image into a Word document and then save that document as Pdf using Word the text in the Pdf is not selectable.
If you manually use Excel to copy the cell as picture into Word and save as Pdf the text is selectable.

As an aside, if you save the docx to pdf using Aspose.Words the text is selectable for both Emfs!

Test.zip (107.1 KB)

@ServerSide527,

Thanks for the sample files and sample code.

After an initial test, I observed the issue as you mentioned by using your sample code with your template file. I found that the Emf produced by Aspose.Cells has unselectable text in Word to Pdf conversion.

I have logged a ticket with an id “CELLSNET-45513” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

Thank you

@ServerSide527,

After investigating our Aspose.Cells generated EMF file, Microsoft Excel generated EMF file and Microsoft Word generated PDF file, we find that it is the EMF plus records in the image that cause Microsoft Word treating the text in the image as paths/canvas.
Our Aspose.Cells generated EMF file and Microsoft Excel generated EMF file are both EmfPlusDual type. Our Aspose.Cells generated EMF file has EMF plus records like “EmfPlus-DrawString” record, but Microsoft Excel generated EMF file doesn’t have EMF plus records like “EmfPlus-DrawString” record and it uses “EmfPlus-GetDC” record to indicate that using the subsequent EMF only records.

Using the following code to remove EMF plus records, the generated EMF file will be Ok.
e.g
Sample code:

    var book = new Workbook("test.xlsx");
    Worksheet sheet = book.Worksheets[0];
    var options = new ImageOrPrintOptions
    {
        ImageFormat = ImageFormat.Emf,
        OnePagePerSheet = true,

    };

    using (MemoryStream ms = new MemoryStream())
    {
        new SheetRender(sheet, options).ToImage(0, ms);

        ReSaveImageToEmfOnly(ms, "test.emf");
    } 

//convert function code:
internal 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();
        }
    }
} 

Let us know if you still have any issue.

Thank you.

Hi,

I am sorry to say but converting to EmfOnly is not a viable solution whatsoever.
Using EmfOnly seriously degrades the quality of the output and sometimes even gives wrong results.

Using the code above on a more complex Excel file you will see that the lines in the Chart are all jagged.
I have plenty of other examples where EmfOnly will produce a bad result on charts and tables. So this is clearly not an option, especially as Excel manages to create an Emf file that is both well rendered and has the ability to select text in a Word created Pdf.

EmfOnly.zip (42.4 KB)

@ServerSide527,

Thanks for sharing further details and sample files.

Your concerns make sense but we need to evaluate it thoroughly. I have logged your concerns with sample files against your issue “CELLSNET-45513” into our database. Our concerned developer from product team will analyze your issue further.

Once we have any new information, we will let you know here.

Thank you.