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.

The issues you have found earlier (filed as CADNET-1069) have been fixed in this update.

Hello, how can I solve the same problem in aspose.cad for java

@hejiusan

This issue has been marked as fixed for both .NET and Java. You can please try using latest Aspose.CAD for Java version on your end by referring to following sample code example.

Hello, how can I make the information in the text tag not wrap after converting dwg to svg format through cad for javaimage.png (28.5 KB)

@hejiusan

Unfortunately, I have not been able to extract the deisired output that you want to achive using Aspose.CAD. Can you please share what you are getting out from API and what is expected.

I want the content in the <> to look like this when I convert it to an SVG, but not when I convert it.

public static void main(String[] args){
String absParsingFile=“C:\Users\10859\Desktop\zh23.dwg”;
com.aspose.cad.Image cadImage = com.aspose.cad.Image.load(absParsingFile);

   CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
   rasterizationOptions.setPageWidth(1920);
   rasterizationOptions.setPageHeight(1080);
   rasterizationOptions.setAutomaticLayoutsScaling(true);
   rasterizationOptions.setNoScaling (false);
   rasterizationOptions.setContentAsBitmap(true);  //图片处理时防止内存溢出
   rasterizationOptions.setLayouts(new String[] {"Model"});
   rasterizationOptions.setDrawType(CadDrawTypeMode.UseDrawColor);

   SvgOptions svgOptions = new SvgOptions();
   svgOptions.setTextAsShapes(false);
   svgOptions.setVectorRasterizationOptions(rasterizationOptions);

   
   // Set Graphics options
   //抗锯齿
   rasterizationOptions.getGraphicsOptions().setSmoothingMode(SmoothingMode.HighQuality);
   //文本边缘处理
   rasterizationOptions.getGraphicsOptions().setTextRenderingHint(TextRenderingHint.AntiAliasGridFit);
   //控制缩放质量
   rasterizationOptions.getGraphicsOptions().setInterpolationMode(InterpolationMode.HighQualityBicubic);

   cadImage.save("C:\\Users\\10859\\Desktop\\zh123.svg", svgOptions);
   System.out.println("打印成功...");
   cadImage.close();
}

image.png (28.5 KB)
2.png (4.5 KB)

@hejiusan

Please share the source DWG file along with generated SVG so that I may log the request in our issue tracking system for further investigation and resolution.