Skip to content

Metafile manipulations

Kunaal

Asked Aug 26, 2006, 10:50 PM EDT1 answer
Share
LinkedInX

Hi!

 

Need your ideas urgently! I have a metafile which I wish to convert to PDF on the fly. The idea is to create a metafile template with placeholder text, which will be parsed and replaced by user information at runtime before generating the PDF. When editing the metafile, I have progressed to the following steps:

 

1.      Called the Graphics.EnumerateMetaFile() method, which calls the callback method (lets call it ‘Play’)

2.      Called the callback method and obtain the record data

 

C#
public bool Play(EmfPlusRecordType recordType, int flags, int datasize, IntPtr data, PlayRecordCallback callback)
{
byte[] dataArray = null;
      if (data != IntPtr.Zero)
      {
                  dataArray = new byte[datasize];
             Marshal.Copy(data, dataArray, 0, datasize);
      }

 

3.      Checked whether the record pertains to writing text on the wmf as follows:

 

if (recordType == EmfPlusRecordType.DrawString)

 

  1. Called the Metafile.PlayRecord() method to draw the new metafile.

 

mf.PlayRecord(recordType, flags, datasize, dataArray);

 

What I’m unable to do is, to parse the dataarray (which contains record data), such that I can replace existing text with new text.

 

Thanks a LOT for any insights.

 

Regards,

Kunaal

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi,

    First you need to read trough the documentation of the WMF, EMF and EMF+ and get data layout for each record you are interested in .

    Then Use the "BitConverter" to read data form the byte array and covert it to correct data type as defined in the record information.

    Examples:
    Single val = BitConverter.ToSingle(DataArray, Position);
    Double val = BitConverter.ToDouble(DataArray, Position);
    System.IO.MemoryStream ms = new System.IO.MemoryStream(DataArray, Position, size);
    Image img = System.Drawing.Image.FromStream(ms);
    0