1

I have tried the below code to copy mathematical expressions from word document and save them as images but it doesn't work.

foreach (OMath math in doc.Content.OMaths)
                {
                    math.Range.Select();
                    math.Range.CopyAsPicture();

                    System.Windows.Forms.IDataObject dobj = System.Windows.Forms.Clipboard.GetDataObject();

                    if( dobj.GetDataPresent(typeof(System.Drawing.Bitmap)) )
                    {
                        System.Drawing.Bitmap bitmap = (Bitmap)dobj.GetData(typeof(System.Drawing.Bitmap));
                        bitmap.Save("C:\\tempFolder\\Image" + cnt + ".bmp", ImageFormat.Bmp);
                    }

                    cnt++;

                }

Anyone can help? Thanks in advance.

  • Do you have debugged? Does the `bitmap.save()` code has been reached? – Colin O'Coal Sep 24 '12 at 09:52
  • I have debugged , dobj.GetDataPresent does not have the type: System.Drawing.Bitmap , I also tried to remove the if and tried the below code instead: MemoryStream memoryStream = (MemoryStream)dobj.GetData(DataFormats.MetafilePict); Image image = Image.FromStream(memoryStream); image.Save("C:\MyDirectory\\Image" + cnt + ".jpg", ImageFormat.Jpeg); but i had a "Parameter is not valid" exception on : Image.FromStream(memoryStream); – Salam Succar Sep 25 '12 at 05:38
  • Did you make your sample based on that post: http://stackoverflow.com/questions/4870267/converting-images-from-word-document-into-bitmap-object? – Colin O'Coal Sep 25 '12 at 08:03
  • Yes it works fine with inline shapes, but not with word equations from OMath library – Salam Succar Sep 25 '12 at 08:38
  • Hard job ... I'll try to reproduce that today in the evening. – Colin O'Coal Sep 25 '12 at 14:06

0 Answers0