We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cannot ungroup EMF in Word or Powerpoint

Hi, when I render a Powerpoint Slide into a Metafile Graphics Context, I obtain a byte[] array with proper EMF Format which I can successfully save into an *.emf File or embed into Word.
But when I try to “ungroup” the EMF Graphic in Word or Powerpoint I obtain an empty graphic.
Can I modify the Rendering so that the EMF is editable in Word or PPT?
This is my code:
public static byte[] PptxAsEmf(this ISlide slide, Drawing.SizeF slideSize)
{
using (var stream = new MemoryStream()) {
using (var graphics = CreateEmf(stream, bounds))
{
graphics.SetClip(new Drawing.RectangleF(0, 0, (int)bounds.Width, (int)bounds.Height));
// graphics.SetGraphicsQuality();
slide.RenderToGraphics(false, graphics, (int)bounds.Width, (int)bounds.Height);
//ImagePixelFormat pf = ImagePixelFormat.Format32bppArgb
}
stream.Flush();
return stream.ToArray();
}
}

    public static Drawing.Graphics CreateEmf(this Stream stream, Rect bounds = new Rect()) {
        if (bounds.Width  <= 0 ||
            bounds.Height <= 0) {
            bounds = new Rect(0, 0, 1, 1);
        } //use a dummy Image to retrieve a Graphics Context
        return CreateMetaFile(stream, Math.Max(bounds.Width, 1), Math.Max(bounds.Height, 1)).CreateGraphics();
    }
    public static Imaging.Metafile CreateMetaFile(Stream stream, double width, double height) {
        var offScreenBufferGraphics = Drawing.Graphics.FromHwndInternal(IntPtr.Zero);
        //using () 
        {
            IntPtr deviceContextHandle = offScreenBufferGraphics.GetHdc();
            var metaFile = new Imaging.Metafile(
                stream,
                deviceContextHandle,
                new Drawing.RectangleF(0, 0, (float)width, (float)height),
                Imaging.MetafileFrameUnit.Pixel,
                Imaging.EmfType.EmfPlusOnly);
            //TODO: offScreenBufferGraphics.ReleaseHdc();
            return metaFile;
        }
    }

@mheuer,

I have observed the information shared by you and have not been able to completely understand that. Can you please provide the working sample project along with source files, generated output and desired output files. I am unable to use the the presently shared code as it is not complete and with not source files. Please share the requested information so that I may proceed further to help you out.

Hi again, here is a C# Solution that generates a “Slide.emf” File from the first Slide in “Slides.pptx”.
Please copy that and paste it in a Word Document.
If you then right-click on the Graphics and choose “Group/Ungroup” from the Context Menu, the Graphic disappears.
This doesn’t happen when I render a Graphic into the Metafile-Context using Code. These EMFs will be split into their individual lines so I can edit them after “ungroup”.AsposeEmfRepro.zip (26.2 KB)

As an example try the same with the attached zipped *.emf file, there you can edit the Graphic after “ungroup”.DocxEmfGraphic.zip (4.5 KB)

@mheuer,

Thank you for providing detailed information. I have worked over the scenario and have been able to observe the issue specified. An issue with ID SLIDESNET-40806 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.