A Metafile is a file that stores records which describe a graphics operations sequence of graphics which can be recorded and played back. These files may contain digital graphics such as vector images, bitmaps formats or other data.
PDF for .NET supports metafiles and allows you to draw metafiles in a Pdf document. It provides the DrawImage method which can be used to render bitmaps and metafiles. When used with metafiles, it enumerates the drawing commands in the metafile and translates them into low-level drawing primitives. This results in resolution-independent images.
The following image shows a metafile rendered in a Pdf document.
To render a metafile in a Pdf document, use the following code. In this example, we have used a metafile named sample.wmf and drew it on the PDF using DrawImage method of the C1PdfDocument class.
C# |
Copy Code
|
---|---|
Metafile page = (Metafile)Metafile.FromFile("../../../sample.wmf"); pdf.DrawImage(page, pdf.PageRectangle); // Save to file pdf.Save("MetaFile.pdf"); ProcessStartInfo psInfo = new ProcessStartInfo { FileName = "MetaFile.pdf", UseShellExecute = true }; Process.Start(psInfo); |
PDF for .NET also supports EMF+ metafiles. According to Microsoft, EMF+ is an extension to EMF that allows GDI+ records to be stored. Previously, all metafiles were transformed to EMF Only. EMF+ metafiles are no longer transformed; therefore, they do not lose their context due to transformation.