Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 19, 2021 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/15d7f2f7de393eb87f75096b3d59c190 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/15d7f2f7de393eb87f75096b3d59c190 to your computer and use it in GitHub Desktop.
Convert EMF or WMF to SVG Programmatically using C#
// Path to input EMF file
string sourcePath = dataDir + @"test.emf";
// Path for output SVG image
string destPath = dataDir + @"EMF_out.svg";
// Load input EMF file
using (Image image = Image.Load(sourcePath))
{
// Initilaize EmfRasterizationOptions class object
EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
emfRasterizationOptions.BackgroundColor = Color.White;
emfRasterizationOptions.PageWidth = image.Width;
emfRasterizationOptions.PageHeight = image.Height;
// Save output SVG image
image.Save(destPath, new SvgOptions() { VectorRasterizationOptions = emfRasterizationOptions });
}
// Path to input WMF file
string sourcePath = dataDir + @"TextHintTest.wmf";
// Path to output SVG image
string destPath = dataDir + @"WMF_out.svg";
// Load input WMF file
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourcePath))
{
// Initialize WmfRasterizationOptions instance
WmfRasterizationOptions wmfRasterizationOptions = new WmfRasterizationOptions();
wmfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.White;
wmfRasterizationOptions.PageHeight = image.Height;
wmfRasterizationOptions.PageWidth = image.Width;
// Save output SVG image
image.Save(destPath, new SvgOptions() { VectorRasterizationOptions = wmfRasterizationOptions });
}
// Load input EMF file
using (Image image = Image.Load(dataDir + "Test.emf"))
{
// Specify EmfRasterizationOptions instance
EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
emfRasterizationOptions.BackgroundColor = Color.White;
emfRasterizationOptions.PageWidth = image.Width;
emfRasterizationOptions.PageHeight = image.Height;
// Save output SVG file
image.Save(dataDir + "TextAsShapes_out.svg", new SvgOptions
{
// Set boolean property to render text as shapes
VectorRasterizationOptions = emfRasterizationOptions,
TextAsShapes = true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment