Word 2002/2003 will not import EMFPlusOnly files created by .NET p

S

Sebastian

EMF+ (Plus Only Records) files generated using VB.NET program do not seem to
import into word document when using Insert->Picture->From File menu or
corresponding macro command. Word shows convert file dialog box and after
Enhanced Mete File is selected shows “An error occurred while importing this
file. FilePathâ€. However, when using drag and drop method, file inserts just
fine and any consecutive insertions of the same file can be done using menu
without any problems. File seems to be OK since it opens up just fine in MS
Picture and Fax viewer. Also, VISIO imports .NET generated EMF+ only files
without any problems using same menu command as in Word. The problem with
Word can be solved by generating and inserting EMF dual (GDI+ and OLD GDI
Records) file. However, overhead is enormous especially with complex graphics
and I don't consider it to be a viable solution. I have SP1 for Word 2003
installed. I tried both .NET 1.1 and .NET 2 with same results. How do I solve
the problem? Is there a work around for this? Is it Word or .NET bug?
Can I produce EmfPlusOnly files from VISIO? I would like to reduce overhead
on VISIO EMF files as well and also verify that Word can import those.

PS. Here is the VB.NET code that I use to produce MetaFile

Public Function CreateMetaFile(ByRef Stream As System.IO.Stream) As
Drawing.Imaging.Metafile
Dim Graphics As Graphics
Dim ptrHDC As IntPtr
Dim MetaFile As Drawing.Imaging.Metafile
Dim bm As New Bitmap(1600, 1200, Imaging.PixelFormat.Format32bppRgb)
Graphics = Graphics.FromImage(bm) ' Create graphics context
ptrHDC = Graphics.GetHdc() ' Get the device context from the
graphics context
MetaFile = New Drawing.Imaging.Metafile _
(Stream, ptrHDC, New Rectangle(0, 0, 1600, 1200), _
Drawing.Imaging.MetafileFrameUnit.Pixel,
Drawing.Imaging.EmfType.EmfPlusOnly) 'Create a new Enhanced Metafile from
the device context
Graphics.ReleaseHdc(ptrHDC) ' Release the device context
Graphics.Dispose()
Return MetaFile
End Function

Public Sub WriteEMF()

Dim emfStream As New System.IO.FileStream("C:\temp\drawing.emf,
IO.FileMode.Create) 'create & open file
Dim eMetaFile As Drawing.Imaging.Metafile = CreateMetaFile(emfStream)
Dim gr As Graphics = Graphics.FromImage(eMetaFile) ' Get graphics context
from the Enhanced Metafile

'I use gr object to draw figures and lines here. I tried very simple
drawings like color filled rectangle.

eMetaFile.Dispose() 'Dispose meta file object
emfStream.Close() 'Close file

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top