Free Support Forum - aspose.com

Convert from .DWG/.DXF to .EMF and .SVG

Hello,
I’m evaluating your Aspose.CAD product and was wondering if my specific conversions are supported. I’ve downloaded the demo and have code to perform the conversion to .emf:

  openFileDialog1.InitialDirectory = "D:\\DWG\\Aspose";
  openFileDialog1.Filter = "AutoCad Files(*.DWG;*.DXF)|*.DWG;*.DXF|All Files (*.*)|*.*";
  if (openFileDialog1.ShowDialog() != DialogResult.OK)
  {
    return;
  }
  string cadFileName = openFileDialog1.FileName;
  string emfFileName = Path.Combine(Path.GetDirectoryName(cadFileName), Path.GetFileNameWithoutExtension(cadFileName) + ".emf");

  using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(cadFileName))
  {
    Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
    rasterizationOptions.PageWidth = 4000;
    rasterizationOptions.PageHeight = 3000;

    CAD.ImageOptionsBase cadEmfImageOptions = new Aspose.CAD.ImageOptions.WmfOptions();
    cadEmfImageOptions.VectorRasterizationOptions = rasterizationOptions;

    // Save EMF
    image.Save(emfFileName, cadEmfImageOptions);
  }

This code appears to work but the text is converted as objects instead of text. Also, I want to make sure I’m using the product for it’s intended purpose.

Thank you.

@BSulek,

I have observed the requirements shared and request you to please provide the source file and generated output with us. Please also share the desired output EMF as well with us and we will investigate that further internally on our end.

Hello,

I have narrowed down and simplified my problem. I’m trying to open a .DWG and save it as a .SVG using the following snippet from your examples: (NOTE: SimpleEntites.dwg is a dwg file that is included in your examples in folder Data\DWG-Drawings)

public static void Run() {
  //ExStart:ExportToSVG
  // The path to the documents directory.
  string MyDir = RunExamples.GetDataDir_DWGDrawings();
  using (Image image = Image.Load(MyDir + "SimpleEntites.dwg"))
  {
    var options = new SvgOptions();
    options.TextAsShapes = false;

    image.Save(MyDir + "SimpleEntites.svg", options);
  }
//ExEnd:ExportToSVG
}

This code executes just fine with options.TextAsShapes = false;, and produces the attached SimpleEntites.svg. I’m trying to get the text on the drawing (i.e. “My Multiline text…”) to convert as <text></text> svg elements (like your “Evaluation only…” message) instead of <path/> elements. I assume that I would use options.TextAsShapes = true; to achieve that result. Is that the case? If so, unfortunately when I set TextAsShapes = true, I get the exception in the attached .png file. Is there something that I’m doing wrong, or don’t have setup quite right?

Thanks again.SimpleEntites.zip (220.8 KB)

@BSulek,

I have observed the issue shared. Can you please confirm if you are using Aspose.CAD for .NET using license. The message, Evaluation only appears when you using product with valid license. Can you please try using the product with valid license and share feedback.

I was able to get an evaluation license so the “Evaluation only…” message goes away. I no longer get the exception but I still do not get the desired result though.

I’m trying to have the text in the resulting .svg file end up as <text></text> svg elements instead of <path/> elements. Is there a way to do this?

After a bit of further digging, I found this issue in your support forum, which is exactly my issue:

To reiterate, I need to be able to save text entities as text NOT shapes or polylines when converting from .DWG to .SVG. I like everything else about the toolset and am also going to purchase Aspose.Imaging if I can get this working, but I have to be able to have this functionality.

@BSulek,

I have observed the issue shared you and have created a ticket with ID CADNET-1069 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.