0

Currently all the EMF files which I generated through Aspose engine are in EMF dual mode.

It would be very nice if someone could enlighten me on how to generate an EMFPlus file through Aspose. If you can provide me a sample EMFPlus file, which is not in Dual mode, that will be great.

Or, please let me know from where I can download it from internet.

sv k
  • 11
  • 3

1 Answers1

1

I believe you have posted a similar question in Aspose.Words Support forum therefore I will address your concerns from Aspose.Words prespective first. Please note, Aspose.Words APIs allow you to render the documents in EmfOnly, EmfPlus & EmfPlusWithFallback formats. Please check the following piece of code that converts the input document to EmfPlus format using Aspose.Words for .NET API.

var doc = new Aspose.Words.Document("D:/sample.docx");
var saveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Emf);
saveOptions.MetafileRenderingOptions.EmfPlusDualRenderingMode = Aspose.Words.Saving.EmfPlusDualRenderingMode.EmfPlusWithFallback;
doc.Save("D:/output.emf", saveOptions);

If you intend to convert existing EmfPlusDual images to EmfPlus, you can use the GDI+ routines for this purpose. Please check the following method that accepts the image data in the form of System.IO.Stream and converts it to EmfPlus before saving it back on disc.

    void ReSaveEmfToEmfPlus(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.EmfPlusOnly);
          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();
          }
      }
   }

If you are looking for EmfPlus samples, you can search them over the internet with appropriate keywords, and hopefully you will be able to find the desired files.

I work with Aspose as Developer Evangelist.

Community
  • 1
  • 1
Prorata
  • 483
  • 3
  • 10
  • Thanks Prorata, I had tried the code and generated EMF files which was in EMFplusonly mode.But the issue with those emfplus files are, while parsing it consists only EMFPlusObject record type with object type as 'image' ie. the whole data in EMF, even the text(EMFPlusDrawstring) and lines(EMFPlusDrawPath) are converted into an a single EMFPlusObject image object type, which is not required for me. – sv k Sep 10 '15 at 11:10
  • Could you please enlighten me how to convert a dualmodeEMF to EMFPlusonly mode emf file; I want the new EMFPlusOnly file with its actual emfplus recordtypes and not as a single EMFPlusObject record with image objecttype – sv k Sep 10 '15 at 11:13
  • @svk, I am afraid, this is seems to be the default behavior of GDI+ and may not be controlled. I will research further and update you if I can find an alternative solution. – Prorata Sep 11 '15 at 14:19